All notable changes to enum
will be documented in this file
- Drop PHP 7.4 support
- Add
Stringable
interface to enum class - #116
- Add support for
isset()
calls to enum->value
und->label
- #109
- Add support for
isset()
calls to enum->value
und->label
- #109
- Change attribute for PHP 8.1 compatibility
- Added support for PHP 8.1
- Fix
from()
andtryFrom()
methods to do PHP type-juggling (string to integer) - #108 - Fix
tryFrom()
method to catch scalar type-errors - #105
- Add
from()
andtryFrom()
methods to get closer to PHP8.1 native enums - #94 - Deprecate
make()
in favor offrom()
method - #94 - Add flyweight pattern to return the same enum instance for every call - #94
- Add
cases()
method to retrieve all instances of the enum - #79
- Fix problem with
@readonly
annotation and annotation parsing libraries - #92
- Add description to PHPUnit assertion methods - #88
- Add ability to use a
Closure
as value/label map - #87
- Add psalm annotations to seal and lock internals - #85
- Fix extra whitespaces in enum definition doc-blocks - #86
- Fix issue with enums not callable within enum classes - #82
- Add
assertIsEnumValue()
andassertIsEnumLabel()
to\Spatie\Enum\Phpunit\EnumAssertions
- #80
- Fix
\Spatie\Enum\Enum
php-doc@property-read
annotations - #78
- Add Faker provider to generate random enum instances, values and labels
\Spatie\Enum\Faker\FakerEnumProvider
- #74
- Add
\Spatie\Enum\Enum::toValues()
and\Spatie\Enum\Enum::toLabels()
methods - #72
- Add
\Spatie\Enum\Phpunit\EnumAssertions
with a default set of assertions - #71
- Support PHP ^8.0
- Don't cast value to string when serializing to JSON - #68
- Throw
TypeError
if value passed toEnum
construct is notstring
orinteger
- Add missing type-hints and doc-blocks
- Fix unique values and labels
- Flag
EnumDefinition
as internal
- A complete overhaul of the package, all details are discussed in the PR
- Fix for static
isXyz($value)
magic methods tto returnfalse
on invalid value - follow up fix to v2.3.3 - #62
- Fix internal usage of
toArray()
to allow custom array representations #58
- Fix the name if it's matched but isn't the same #50
- Fix for
isEqual()
andisAny()
method doc-tags to acceptmixed
values
- Fix for static method call passed to
__call
within the context of an object
- Allow passing invalid string values to
isEqual()
#39
- Fix
protected
method calls to allow overrides #37
- Make
\Spatie\Enum\Enumerable::isValidIndex/Name/Value()
methods public #36 -
Please note that this could be breaking for custom implementations of the
\Spatie\Enum\Enumerable
interface.
- Add
\Spatie\Enum\Enum::getAll()
method #33
- Fix calling public non-static methods #32
- Fix overriden existing public static methods like
Enum::toArray()
#29
- Add enum map index and value
Enum::MAP_INDEX
andEnum::MAP_VALUE
#25
- Improved static analysis support for
::make
A 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.
- Add
\Spatie\Enum\Enumerable
interface - Add
\Spatie\Enum\Exceptions\DuplicatedIndexException
,\Spatie\Enum\Exceptions\DuplicatedValueException
,\Spatie\Enum\Exceptions\InvalidIndexException
and\Spatie\Enum\Exceptions\InvalidValueException
exceptions - Add
\Spatie\Enum\Enum->getIndex()
method - Add
\Spatie\Enum\Enum::getIndices()
method - Add
\Spatie\Enum\Enum->getValue()
method - Add
\Spatie\Enum\Enum::getValues()
method - Rename
\Spatie\Enum\Enum::from()
to\Spatie\Enum\Enum::make()
- Rename
\Spatie\Enum\Enum::equals()
to\Spatie\Enum\Enum::isEqual()
- Rename
\Spatie\Enum\Enum::isOneOf()
to\Spatie\Enum\Enum::isAny()
- Change
\Spatie\Enum\Enum->__construct()
signature and responsibility - only take index & value and validate them - Change
\Spatie\Enum\Enum::toArray()
return value instead of an array ofvalue => name
it returnsvalue => index
- Drop recursive
\Spatie\Enum\Enum::make()
support from inside of an unstatic method - Drop
\Spatie\Enum\Enum::$map
in favor of\Spatie\Enum\Enum->getIndex()
and\Spatie\Enum\Enum->getValue()
- Update all methods have strict type checks:
index: int
andvalue: string
- Update all methods are compatible with all required types: index, value, name or instance of Enum
- Add support for is* checks
- Support case insensitive enum values (#13)
- initial release