-
Notifications
You must be signed in to change notification settings - Fork 36
Description
-
Ignore all Constants beginning with "__"
This is first at all used by the enum class itself (see point 2) and for extensions of an enum class, where an additional constant shouldn't belong to the enum behaviour. -
add three constants:
a) __FROM_VALUE
b) __FROM_NAME
c) __FROM_ORDINAL -
change the get method:
static public function get($value, self::__FROM_VALUE)
This way you can create enums by ordinal or by constant name.
- About getConstants()
the method name indicates an implementation detail of the enum class. This is not usefull in terms of an enum.
Better we have:
getNames() and getValues()
Additional: We could perhabs readd a toArray() method, where you get the name => value map again, which is currently what getConstants() does.
This again leave to two conclusions:
a) __toString() shoudldn't be final. An "Enum-like-Html-Object" perhabs could need to override the toString() method and rely an getValue() where needed instead.
Having __toString() returning the value is a good default behaviour.
b) toArray() shoudln't be final, too. The output should be changeable. Rely on the other methods instead, if you need ensured behaviour.
c) what should toArray return? Only what currently getConstants() does? Or perhabs also what the default value is and what the current value is?
What do you think?