marc-mabe/php-enum
Native PHP enum implementation via an abstract base class. Extend it to define enumerations from public constants (supports scalars, null, and arrays), create and compare enum instances, and keep a strict set of named values for safer domain modeling.
Full Changelog: https://github.com/marc-mabe/php-enum/compare/v4.7.1...v4.7.2
EnumSet and EnumMapNone
Stringable interface (with stub for PHP < 8)None
None
clone $enumNone
Support PHP 8.1
Same as v4.6.0-rc1 but with updated dev dependencies
ReturnTypeWillChange to EnumMap.offsetGet^1.0.4^0.12.96ReturnTypeWillChange to EnumMap.offsetGetNone
#147 #148 PHP-8 Support
Enum::__clone to be final protected instead of final private (we don't consider this a BC break) - thanks @shmurakamiassert_options#149 Migrate from Travis CI + Scurinizer to Github Workflow + Codecov
None
None
#138 #140 Static analyzer improvements for PHPStan & Psalm
EnumSet & EnumMap#141 Added __debugInfo() for human readable internals of EnumSet & EnumMap for var_dump()
None
None
#138 #140 Static analyzer improvements for PHPStan & Psalm
EnumSet & EnumMap#141 Added __debugInfo() for human readable internals of EnumSet & EnumMap for var_dump()
None
None
EnumSet::getBinaryBitsetLe()Enum::byName()Serializable methods for BC#131 fixed ordinal cache usage of Enum::getName() if ordinal=0
none
EnumSet::isEmpty() and EnumMap::isEmpty()We have worked a lot to make this library even more useful and also optimized the performance a lot! To be able to do so we introduced a couple of BC breaks (please read the changes carefully) but we tried to keep them as small as possible.
Added Immutable EnumSet and EnumMap API
with* methods which will not modify the current object but instead generate a new objectIteratorAggregate with Generator to move the iteration state into an own object and provides much better performanceAdded methods to bulk modify an EnumSet and EnumMap and to instantiate state
iterable second argument to instantiate the stateaddIterable, removeIterable, withIterable, withoutIterableConsistent Method Namings
EnumSet::attach -> EnumSet::addEnumSet::detach -> EnumSet::removeEnumSet::contains -> EnumSet::hasEnumMap::contains -> EnumMap::hasAdded Type-Hints
PHP-7.1
As of moving from Iterator to IteratorAggregate
foreach directly or migrate to getIterator instead
EnumSet::currentEnumSet::keyEnumSet::nextEnumSet::rewindEnumSet::validEnumMap::currentEnumMap::keyEnumMap::nextEnumMap::rewindEnumMap::validEnumMap::seekAs of moving to Genreator
EnumSet or EnumMap the iterator position can move forward onlyEnum[Set|Map]->getIterator()->rewind() throws an exceptionSoft Deprecations
EnumSet::attach please use EnumSet::add insteadEnumSet::detach please use EnumSet::remove insteadEnumSet::contains please use EnumSet::has insteadEnumMap::contains please use EnumMap::has insteadhttps://github.com/marc-mabe/php-enum/issues?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A4.0.0
We have worked a lot to make this library even more useful and also optimized the performance a lot! To be able to do so we introduced a couple of BC breaks (please read the changes carefully) but we tried to keep them as small as possible.
Added Immutable EnumSet and EnumMap API
with* methods which will not modify the current object but instead generate a new objectIteratorAggregate with Generator to move the iteration state into an own object and provides much better performanceAdded methods to bulk modify an EnumSet and EnumMap and to instantiate state
iterable second argument to instantiate the stateaddIterable, removeIterable, withIterable, withoutIterableConsistent Method Namings
EnumSet::attach -> EnumSet::addEnumSet::detach -> EnumSet::removeEnumSet::contains -> EnumSet::hasEnumMap::contains -> EnumMap::hasAdded Type-Hints
All public methods have argument and return type-hints where possible.
PHP-7.1
As of moving from Iterator to IteratorAggregate
foreach directly or migrate to getIterator instead
EnumSet::currentEnumSet::keyEnumSet::nextEnumSet::rewindEnumSet::validEnumMap::currentEnumMap::keyEnumMap::nextEnumMap::rewindEnumMap::validEnumMap::seekAs of moving to Genreator
EnumSet or EnumMap the iterator position can move forward onlyEnum[Set|Map]->getIterator()->rewind() throws an exceptionSoft Deprecations
EnumSet::attach please use EnumSet::add insteadEnumSet::detach please use EnumSet::remove insteadEnumSet::contains please use EnumSet::has insteadEnumMap::contains please use EnumMap::has insteadhttps://github.com/marc-mabe/php-enum/issues?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A4.0.0
Bugfix release
Changes:
#98 Backported HHVM >3.18.4 & >3.20.2 reports as PHP-7.1 but does not support constant visibility
BC-breaks:
none
\count() instead of count()static::class instead of get_class($this)Enum::get()EnumSet::getValues()EnumMap::search()Enum:has()Patch release of 3.0.x
none
Patch release of 3.0.x
Enum::by*methodsnone
We have worked a lot to make this library even more useful and also optimized the performance a lot! To be able to do so we introduced a couple of BC breaks (please read the changes carefully) but we tried to keep them as small as possible.
Enum::detectConstants() using assertion to check for ambiguous enumerator values
union(), intersect(), diff() and symDiff() support one argument of $others onlypublic function getBit(int $ordinal) : boolpublic function setBit(int $ordinal, bool $bit) : voidEnumMap is serializable, tooSplObjectStorageSerializableArrayAccess, Countable and IteratorSeekableIteratorpublic function attach($enumerator) : void
public function offsetSet($enumerator) : void$map[$enum] = $valuepublic function detach($enumerator): void
public function offsetUnset($enumerator) : voidunset($map[$enum])public addAll(SplObjectStorage $storage) : voidpublic getHash(object $object) : stringpublic removeAll(SplObjectStorage $storage) : voidpublic removeAllExcept(SplObjectStorage $storage) : voidpublic serialize(void) : stringpublic setInfo(mixed $data) : voidpublic unserialize(string $serialized) : voidpublic contains($enumerator) : bool
public offsetExists($enumerator) : bool but returns true on NULL valuespublic function seek(int $pos) : voidpublic function getKeys() : Enum[]public function getValues() : mixed[]public function search($enumerator, bool $strict) : Enum|nullhttps://github.com/marc-mabe/php-enum/issues?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A3.0.0
Enum::detectConstants() using assertion to check for ambiguous enumerator values
AssertionError will be thrown (PHP>=7) or a warning will be triggered (PHP<=5.6) only in case assertions are enabled (development mode) else no error will be thrown. Please read here how assertions work.EnumSet::count() up to 40%We have worked a lot to make this library even more useful and also optimized the performance a lot! To be able to do so we introduced a couple of BC breaks (please read the changes carefully) but we tried to keep them as small as possible.
union(), intersect(), diff() and symDiff() support one argument of $others onlypublic function getBit(int $ordinal) : boolpublic function setBit(int $ordinal, bool $bit) : voidEnumMap is serializable, tooSplObjectStorageSerializableArrayAccess, Countable and IteratorSeekableIteratorpublic function attach($enumerator) : void
public function offsetSet($enumerator) : void$map[$enum] = $valuepublic function detach($enumerator): void
public function offsetUnset($enumerator) : voidunset($map[$enum])public addAll(SplObjectStorage $storage) : voidpublic getHash(object $object) : stringpublic removeAll(SplObjectStorage $storage) : voidpublic removeAllExcept(SplObjectStorage $storage) : voidpublic serialize(void) : stringpublic setInfo(mixed $data) : voidpublic unserialize(string $serialized) : voidpublic contains($enumerator) : bool
public offsetExists($enumerator) : bool but returns true on NULL valuespublic function seek(int $pos) : voidpublic function getKeys() : Enum[]public function getValues() : mixed[]public function search($enumerator, bool $strict) : Enum|nullhttps://github.com/marc-mabe/php-enum/issues?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A3.0.0
Bugfix release
Changes:
#82 EnumSet::setBinaryBitset*(): fixed logic of 'truncate out-of-range bits of last byte'
BC-breaks:
none
https://github.com/marc-mabe/php-enum/pulls?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A2.3.1
(No changes since 2.3.0-rc1)
##Fixed:
##Fixed:
Bugfix release
Changes:
#60 Infinitive loop on counting an empty set based on an empty enumeration
BC-breaks:
none
https://github.com/marc-mabe/php-enum/pulls?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A2.2.1
Feature release of the 2.x branch.
Changes:
Enum::has()BC-breaks:
https://github.com/marc-mabe/php-enum/pulls?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A2.2.0
How can I help you explore Laravel packages today?