spatie/enum
Obsolete: PHP 8.1+ has native enums (recommended). Spatie Enum provides strongly typed, object-based enums for older PHP versions, enabling IDE-friendly static analysis and refactoring. Define enums via @method annotations and call StatusEnum::draft().
Stringable interface to enum class - #116isset() calls to enum ->value und ->label - #109cases() method to retrieve all instances of the enum - #79[@readonly](https://github.com/readonly) annotation and annotation parsing libraries - #92Closure as value/label map - #87assertIsEnumValue() and assertIsEnumLabel() to \Spatie\Enum\Phpunit\EnumAssertions - #80\Spatie\Enum\Enum php-doc [@property-read](https://github.com/property-read) annotations - #78\Spatie\Enum\Enum::toValues() and \Spatie\Enum\Enum::toLabels() methods - #72\Spatie\Enum\Phpunit\EnumAssertions with a default set of assertions - #71TypeError if value passed to Enum construct is not string or integerEnumDefinition as internaltoArray() to allow custom array representations #58isEqual() and isAny() method doc-tags to accept mixed values__call within the context of an objectisEqual() #39protected method calls to allow overrides #37\Spatie\Enum\Enumerable::isValidIndex/Name/Value() methods public #36Please note that this could be breaking for custom implementations of the
\Spatie\Enum\Enumerableinterface.
\Spatie\Enum\Enum::getAll() method #33Enum::toArray() #29Enum::MAP_INDEX and Enum::MAP_VALUE #25::makeA full major rework of the Enum class - we try to list all changes, for more details you can check out the PR and the Issue.
\Spatie\Enum\Enumerable interface\Spatie\Enum\Exceptions\DuplicatedIndexException, \Spatie\Enum\Exceptions\DuplicatedValueException, \Spatie\Enum\Exceptions\InvalidIndexException and \Spatie\Enum\Exceptions\InvalidValueException exceptions\Spatie\Enum\Enum->getIndex() method\Spatie\Enum\Enum::getIndices() method\Spatie\Enum\Enum->getValue() method\Spatie\Enum\Enum::getValues() method\Spatie\Enum\Enum::from() to \Spatie\Enum\Enum::make()\Spatie\Enum\Enum::equals() to \Spatie\Enum\Enum::isEqual()\Spatie\Enum\Enum::isOneOf() to \Spatie\Enum\Enum::isAny()\Spatie\Enum\Enum->__construct() signature and responsibility - only take index & value and validate them\Spatie\Enum\Enum::toArray() return value instead of an array of value => name it returns value => index\Spatie\Enum\Enum::make() support from inside of an unstatic method\Spatie\Enum\Enum::$map in favor of \Spatie\Enum\Enum->getIndex()and \Spatie\Enum\Enum->getValue()index: int and value: stringHow can I help you explore Laravel packages today?