CEnumerable - huh?

What possible purpose does the CEnumerable class serve?




class CEnumerable

{

}



And in the example:


class TextAlign extends CEnumerable

{

    const Left='Left';

    const Right='Right';

}



And in the documentation:

So, yeah - PHP does all of that. Whether you extend this class or not.

Perhaps you have some brilliant as of yet unimplemented idea for what this class would do in the future? :slight_smile:

The only possible point of extending this class, is to say, "yes, I adhere to the standards set forth in the documentation." - if that is the purpose of this class, perhaps the documentation should clarify this.

I could think of useful things this class could actually do - such as actually making the values enumerable (via Reflection), and providing user-friendly display-names for each value, and providing a user-friendly display-name for a NULL value when presenting the options in a user-interface (e.g. dropdowns, radio-buttons, checkbox-groups).

Perhaps something to consider for Yii 2.0? :slight_smile:

imho this should behave in a similar way to SplEnumarable, for integrity checks and typehints.

The below isn’t supported, just ideas:




class YourEnum extends CEnumerable {

    const SOMETHING = 1;

    const SOMETHING_ELSE = 2;

}



using it:




class Foo extends CComponent {

    public function blah() {

        return $this->nonsense(new YourEnum(YourEnum::SOMETHING));

    }

    public function nonsense(YourEnum $val) {

         echo $val + 1; // $val must be one of the items in the enum

    }

}



CEnumerable seems to be used in


CPropertyValue::ensureEnum($value,$enumclass)

which is a helper method supposed to be used in setters.

To complete with an example, I just did something like this:




        public function setOperator($value) {

	    $const=CPropertyValue::ensureEnum($value,'SmsOperator');

	    $this->sms_operator_reference = constant("SmsOperator::$const");

	}