paillechat/php-enum
PHP 7+ enum library: define enums by extending Enum and declaring constants, then instantiate via static named calls (IssueType::ONE()). Instances are strict-equal singletons, work with in_array/type hints, and can convert to/from names.
Fix invalid deprecations for __toString() calls
createByName static constructor, useful for deserialization purposes.Example:
$apiValue = 'bar';
$enum = MyEnum::createByName(strtoupper($apiValue));
Implemented hard deprecations for calls to be removed or changed in 2.0
equals - use == comparison, upgrade to === on 2.0__construct. Use MyEnum::createByName('BAR') or MyEnum::BAR()getValue. Cast to string instead. Will return enum value until 2.0, enum name after.toInt will be removed. Switch to name based enumsImplemented createByName function to instantiate enum by constant name - preferred option for deserializing purpose. example:
$apiValue = 'bar';
$value = MyEnum::createByName(strtoupper($apiValue))
MyEnum::BAR() syntax.Use one instance of type value everywhere. Possibility to get name of Enum member.
Excplicit equality check method (replace with general strict comparison ===)
Remove any value management features (enums are about named instances)
Now we can get available values without instantiate class.
How can I help you explore Laravel packages today?