Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Enum Laravel Package

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.

View on GitHub
Deep Wiki
Context7
v4.7.2

What's Changed

Full Changelog: https://github.com/marc-mabe/php-enum/compare/v4.7.1...v4.7.2

v4.7.1

Improvements

Bugfixes

  • fix deprecation warning in EnumSet and EnumMap

BC-breaks

None

v4.7.0

Improvements

  • #156 Enums explicitly implements Stringable interface (with stub for PHP < 8)

Bugfixes

None

BC-breaks

None

v4.6.1

Bugfixes

  • #155 fix error exception on clone $enum

BC-breaks

None

v3.2.0

Support PHP 8.1

v4.6.0

Same as v4.6.0-rc1 but with updated dev dependencies

v4.6.0-rc1

Improvements

  • #150 PHP-8.1 Support
    • Added Attribute ReturnTypeWillChange to EnumMap.offsetGet
    • Upgrade phpbench to ^1.0.4
    • Upgrade phpstan to ^0.12.96

Bugfixes

  • #150 PHP-8.1 Support
    • Added Attribute ReturnTypeWillChange to EnumMap.offsetGet

BC-breaks

None

v4.4.0

Improvements

  • #147 #148 PHP-8 Support

    • make Enum::__clone to be final protected instead of final private (we don't consider this a BC break) - thanks @shmurakami
    • Restrict required PHP version to be ^7.1 or ^8.0
    • Tests & Benchmark: Removed assertion polyfill code in bootstrap
    • Tests: removed usage of assert_options
  • #149 Migrate from Travis CI + Scurinizer to Github Workflow + Codecov

    • This simplifies test runs on specific PHP versions using official docker images including PHP-8

Bugfixes

None

BC-breaks

None

v4.3.0

Improvements

  • #138 #140 Static analyzer improvements for PHPStan & Psalm

    • Generics for EnumSet & EnumMap
    • Better argument and return type information
    • purity markers for Psalm
  • #141 Added __debugInfo() for human readable internals of EnumSet & EnumMap for var_dump()

Bugfixes

None

BC-breaks

None

v4.3.0-rc1

Improvements

  • #138 #140 Static analyzer improvements for PHPStan & Psalm

    • Generics for EnumSet & EnumMap
    • Better argument and return type information
    • purity markers for Psalm
  • #141 Added __debugInfo() for human readable internals of EnumSet & EnumMap for var_dump()

Bugfixes

None

BC-breaks

None

v4.2.0

Second Minor Release of 4.x

Bugfixes

  • #137 fixed TypeError in EnumSet::getBinaryBitsetLe()
  • #134 fixed check of ambiguous values in Enum::byName()

Changes

  • #136 Added PHP-7.4 in CI
  • #125 PHP 7.4 serializer and wrap old Serializable methods for BC
  • #132 Micro optimizations
v4.1.1

Bugfix release

Changes:

#131 fixed ordinal cache usage of Enum::getName() if ordinal=0

BC-breaks:

none

v4.1.0

First Minor Release of 4.x

Changes

  • #126 Added EnumSet::isEmpty() and EnumMap::isEmpty()
v4.0.0

First stable release of new major version

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.

Changes

  • Added Immutable EnumSet and EnumMap API

    • Added with* methods which will not modify the current object but instead generate a new object
    • Now the iterable interface is using IteratorAggregate with Generator to move the iteration state into an own object and provides much better performance
    • The mutable API will stay untouched. This means that you have the choice to use either the mutable or immutable API depending on your use case.
    • #109 #110 #118
  • Added methods to bulk modify an EnumSet and EnumMap and to instantiate state

    • The constructor supports an iterable second argument to instantiate the state
    • Added methods addIterable, removeIterable, withIterable, withoutIterable
  • Consistent Method Namings

    • We have renamed the following methods to be consistent over all classes.
    • The old method names are marked as deprecated and will trigger a deprecation notice in the last 4.x release and get removed in 5.x
    • EnumSet::attach -> EnumSet::add
    • EnumSet::detach -> EnumSet::remove
    • EnumSet::contains -> EnumSet::has
    • EnumMap::contains -> EnumMap::has
    • #120 #121
  • Added Type-Hints

    • All public methods have argument and return type-hints where possible.
  • PHP-7.1

    • We have raised the required PHP version from 5.6 to 7.1 and removed HHVM support.
    • This has been done to reduce internal complexity, to improve performance and to be able to define type-hints

BC-Breaks

  • As of moving from Iterator to IteratorAggregate

    • removed methods - please use foreach directly or migrate to getIterator instead
      • EnumSet::current
      • EnumSet::key
      • EnumSet::next
      • EnumSet::rewind
      • EnumSet::valid
      • EnumMap::current
      • EnumMap::key
      • EnumMap::next
      • EnumMap::rewind
      • EnumMap::valid
      • EnumMap::seek
  • As of moving to Genreator

    • On iterating an EnumSet or EnumMap the iterator position can move forward only
    • Enum[Set|Map]->getIterator()->rewind() throws an exception
  • Soft Deprecations

    • EnumSet::attach please use EnumSet::add instead
    • EnumSet::detach please use EnumSet::remove instead
    • EnumSet::contains please use EnumSet::has instead
    • EnumMap::contains please use EnumMap::has instead

https://github.com/marc-mabe/php-enum/issues?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A4.0.0

v4.0.0-rc1

First Release Candidate of new major version

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.

Changes

  • Added Immutable EnumSet and EnumMap API

    • Added with* methods which will not modify the current object but instead generate a new object
    • Now the iterable interface is using IteratorAggregate with Generator to move the iteration state into an own object and provides much better performance
    • The mutable API will stay untouched. This means that you have the choice to use either the mutable or immutable API depending on your use case.
    • #109 #110 #118
  • Added methods to bulk modify an EnumSet and EnumMap and to instantiate state

    • The constructor supports an iterable second argument to instantiate the state
    • Added methods addIterable, removeIterable, withIterable, withoutIterable
  • Consistent Method Namings

    • We have renamed the following methods to be consistent over all classes.
    • The old method names are marked as deprecated and will trigger a deprecation notice in the last 4.x release and get removed in 5.x
    • EnumSet::attach -> EnumSet::add
    • EnumSet::detach -> EnumSet::remove
    • EnumSet::contains -> EnumSet::has
    • EnumMap::contains -> EnumMap::has
    • #120 #121
  • Added Type-Hints

  • All public methods have argument and return type-hints where possible.

  • PHP-7.1

    • We have raised the require PHP version from 5.6 to 7.1 and removed HHVM support.
    • This has been done to reduce internal complexity, to improve performance and to be able to define type-hints

BC-Breaks

  • As of moving from Iterator to IteratorAggregate

    • removed methods - please use foreach directly or migrate to getIterator instead
      • EnumSet::current
      • EnumSet::key
      • EnumSet::next
      • EnumSet::rewind
      • EnumSet::valid
      • EnumMap::current
      • EnumMap::key
      • EnumMap::next
      • EnumMap::rewind
      • EnumMap::valid
      • EnumMap::seek
  • As of moving to Genreator

    • On iterating an EnumSet or EnumMap the iterator position can move forward only
    • Enum[Set|Map]->getIterator()->rewind() throws an exception
  • Soft Deprecations

    • EnumSet::attach please use EnumSet::add instead
    • EnumSet::detach please use EnumSet::remove instead
    • EnumSet::contains please use EnumSet::has instead
    • EnumMap::contains please use EnumMap::has instead

https://github.com/marc-mabe/php-enum/issues?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A4.0.0

v2.3.2

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

v3.1.1

First Patch Release of 3.1.x

Changes

  • #107 fixed array to string conversion in EnumMap::offsetGet()
  • copyright 2019
  • \count() instead of count()
  • static::class instead of get_class($this)
  • more strict argument type for Enum::get()
v3.1.0

First Minor Release of 3.x

Changes

  • #96 #106 Support arrays as enum values in phpDoc enhancement
  • #105 added Enum::hasValue() and Enum::hasName()
  • added missing phpdoc @throws
  • fixed return type in phpdoc of EnumSet::getValues()
  • fixed argument type in phpdoc of EnumMap::search()
  • fixed first argument name in phpdoc of Enum:has()
v3.1.0-rc1

First Release Candidate of new minor version

Changes

  • #96 #106 Support arrays as enum values in phpDoc enhancement
  • #105 added Enum::hasValue() and Enum::hasName()
v3.0.2

Patch release of 3.0.x

Changes

  • #99 : Minor phpdoc syntax fix

BC-breaks

none

v3.0.1

Patch release of 3.0.x

Changes

  • #95 : Add description to assert()
  • #98 : HHVM >3.18.4 & >3.20.2 reports as PHP-7.1 but does not support constant visibility
  • Micro-Optimized Enum::by*methods

BC-breaks

none

v3.0.0

New Major Version

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.

Changes

  • #94 optimized Enum::detectConstants() using assertion to check for ambiguous enumerator values
    • this method is called once on initialize an enumeration
  • #68 removed deprecated methods
  • #69 bumped up PHP version to >=5.6
    • new language features helps us to better maintain this library and provides better optimized code
    • we decided to bump up the supported PHP version as PHP-5.3 is outdated for a long time now
    • we decided to still keep PHP-5.6 (even if outdated as well) as this library is still compatible with HHVM. This way HHVM users can use this new version and have more time to migrate
  • #87 added phpbench suite
  • #73 EnumSet::setBinaryBitset*(): now throws an exception on out-of-range bits set
  • #86 refactored EnumSet to be auto based on integer or binary bitset dependent on enumeration size
    • Methods changed:
      • union(), intersect(), diff() and symDiff() support one argument of $others only
    • Methods added:
      • public function getBit(int $ordinal) : bool
      • public function setBit(int $ordinal, bool $bit) : void
  • #70 removed iterator flags for EnumMap
    • the key will be the enumerator object and the value the assigned data
  • #90 #91 #92 Refactor EnumMap
    • if data are serializable the EnumMap is serializable, too
    • no longer based on SplObjectStorage
    • no longer implement Serializable
    • still implements ArrayAccess, Countable and Iterator
    • new implements SeekableIterator
    • Methods removed:
      • public function attach($enumerator) : void
        • please use public function offsetSet($enumerator) : void
        • or direct array access $map[$enum] = $value
      • public function detach($enumerator): void
        • please use public function offsetUnset($enumerator) : void
        • or direct array access unset($map[$enum])
      • public addAll(SplObjectStorage $storage) : void
      • public getHash(object $object) : string
      • public removeAll(SplObjectStorage $storage) : void
      • public removeAllExcept(SplObjectStorage $storage) : void
      • public serialize(void) : string
      • public setInfo(mixed $data) : void
      • public unserialize(string $serialized) : void
    • Methods changed:
      • public contains($enumerator) : bool
        • same as public offsetExists($enumerator) : bool but returns true on NULL values
    • Methods added:
      • public function seek(int $pos) : void
      • public function getKeys() : Enum[]
      • public function getValues() : mixed[]
      • public function search($enumerator, bool $strict) : Enum|null

https://github.com/marc-mabe/php-enum/issues?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A3.0.0

v3.0.0-rc3

Third Release Candidate of new major version

Changes

  • #94 optimized Enum::detectConstants() using assertion to check for ambiguous enumerator values
    • this method is called once on initialize an enumeration

BC-breaks:

  • #94 Now on initialize an enumeration with ambiguous enumerator values an 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.
v3.0.0-rc2

Second Release Candidate of new major version

Changes

  • optimized EnumSet::count() up to 40%

BC-breaks:

  • none
v3.0.0-rc1

First Release Candidate of new major version

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.

Changes

  • #68 remove deprecated methods
  • #69 bumped up PHP version to >=5.6
    • new language features helps us to better maintain this library and provides better optimized code
    • we decided to bump up the supported PHP version as PHP-5.3 is outdated for a long time now
    • we decided to still keep PHP-5.6 (even if outdated as well) as this library is still compatible with HHVM. This way HHVM users can use this new version and have more time to migrate
  • #87 added phpbench suite
  • #73 EnumSet::setBinaryBitset*(): now throws an exception on out-of-range bits set
  • #86 refactored EnumSet to be auto based on integer or binary bitset dependent on enumeration size
    • Methods changed:
      • union(), intersect(), diff() and symDiff() support one argument of $others only
    • Methods added:
      • public function getBit(int $ordinal) : bool
      • public function setBit(int $ordinal, bool $bit) : void
  • #70 removed iterator flags for EnumMap
    • the key will be the enumerator object and the value the assigned data
  • #90 #91 #92 Refactor EnumMap
    • if data are serializable the EnumMap is serializable, too
    • no longer based on SplObjectStorage
    • no longer implement Serializable
    • still implements ArrayAccess, Countable and Iterator
    • new implements SeekableIterator
    • Methods removed:
      • public function attach($enumerator) : void
        • please use public function offsetSet($enumerator) : void
        • or direct array access $map[$enum] = $value
      • public function detach($enumerator): void
        • please use public function offsetUnset($enumerator) : void
        • or direct array access unset($map[$enum])
      • public addAll(SplObjectStorage $storage) : void
      • public getHash(object $object) : string
      • public removeAll(SplObjectStorage $storage) : void
      • public removeAllExcept(SplObjectStorage $storage) : void
      • public serialize(void) : string
      • public setInfo(mixed $data) : void
      • public unserialize(string $serialized) : void
    • Methods changed:
      • public contains($enumerator) : bool
        • same as public offsetExists($enumerator) : bool but returns true on NULL values
    • Methods added:
      • public function seek(int $pos) : void
      • public function getKeys() : Enum[]
      • public function getValues() : mixed[]
      • public function search($enumerator, bool $strict) : Enum|null

https://github.com/marc-mabe/php-enum/issues?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A3.0.0

v2.3.1

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

v2.3.0

Feature release of the 2.x branch.

(No changes since 2.3.0-rc1)

New:

  • #63: EnumSet: support for Little- and Big-Endian binary bitsets
    • Added EnumSet::getBinaryBitsetLe() : string
    • Added EnumSet::setBinaryBitsetLe(string $bitset)
    • Added EnumSet::getBinaryBitsetBe() : string
    • Added EnumSet::setBinaryBitsetBe(string $bitset)
  • #64: EnumSet: added isEqual(), isSubset() and isSuperset()
    • Added EnumSet::isEqual(EnumSet $other) : bool
    • Added EnumSet::isSubset(EnumSet $other) : bool
    • Added EnumSet::isSuperset(EnumSet $other) : bool
  • #66: EnumSet: added methods union(), intersect(), diff() and symDiff()
    • Added EnumSet::union(EnumSet ...$others) : EnumSet
    • Added EnumSet::intersect(EnumSet ...$others) : EnumSet
    • Added EnumSet::diff(EnumSet ...$others) : EnumSet
    • Added EnumSet::symDiff(EnumSet ...$others) : EnumSet
  • #65: EnumSet: added getEnumerators(), getNames() and getValues()
    • Added EnumSet::getEnumerators() : Enum[]
    • Added EnumSet::getValues() : mixed[]
    • Added EnumSet::getNames() : string[]
  • #78: Added static Enum::getValues(), Enum::getNames() and Enum::getOrdinals()
    • Added Enum::getValues() : mixed[]
    • Added Enum::getNames() : string[]
    • Added Enum::getOrdinals() : int[]
  • #80: refactored Enum::getBy* to Enum::by*
    • Renamed Enum::getByName() -> Enum::byName()
    • Renamed Enum::getByOrdinal() -> Enum::byOrdinal()
    • Added Enum::byValue()
  • #59: handle class constant visibility added in PHP-7.1
  • #67: optimized EnumSet::count() by 30% to 240%
  • #75: optimized EnumSet by using EnumSet properties directly instead of getter methods

##Fixed:

  • #71: EnumSet::setBinaryBitset*(): out-of-range bits of last byte not truncated
  • #77: Missing additional check on Enum::is() to return TRUE in some circumstances

Deprecations:

  • #63 :EnumSet::getBitset() : string
  • #63: EnumSet::setBitset(string $bitset)
  • #79: Enum::clear()
  • #80: Enum::getByName()
  • #80: Enum::getByOrdinal()

BC-breaks:

  • none

https://github.com/marc-mabe/php-enum/milestone/11?closed=1

v2.3.0-rc1

First Release Candidate of 2.3.0.

New:

  • #63: EnumSet: support for Little- and Big-Endian binary bitsets
    • Added EnumSet::getBinaryBitsetLe() : string
    • Added EnumSet::setBinaryBitsetLe(string $bitset)
    • Added EnumSet::getBinaryBitsetBe() : string
    • Added EnumSet::setBinaryBitsetBe(string $bitset)
  • #64: EnumSet: added isEqual(), isSubset() and isSuperset()
    • Added EnumSet::isEqual(EnumSet $other) : bool
    • Added EnumSet::isSubset(EnumSet $other) : bool
    • Added EnumSet::isSuperset(EnumSet $other) : bool
  • #66: EnumSet: added methods union(), intersect(), diff() and symDiff()
    • Added EnumSet::union(EnumSet ...$others) : EnumSet
    • Added EnumSet::intersect(EnumSet ...$others) : EnumSet
    • Added EnumSet::diff(EnumSet ...$others) : EnumSet
    • Added EnumSet::symDiff(EnumSet ...$others) : EnumSet
  • #65: EnumSet: added getEnumerators(), getNames() and getValues()
    • Added EnumSet::getEnumerators() : Enum[]
    • Added EnumSet::getValues() : mixed[]
    • Added EnumSet::getNames() : string[]
  • #78: Added static Enum::getValues(), Enum::getNames() and Enum::getOrdinals()
    • Added Enum::getValues() : mixed[]
    • Added Enum::getNames() : string[]
    • Added Enum::getOrdinals() : int[]
  • #80: refactored Enum::getBy* to Enum::by*
    • Renamed Enum::getByName() -> Enum::byName()
    • Renamed Enum::getByOrdinal() -> Enum::byName()
    • Added Enum::byValue()
  • #59: handle class constant visibility added in PHP-7.1
  • #67: optimized EnumSet::count() by 30% to 240%
  • #75: optimized EnumSet by using EnumSet properties directly instead of getter methods

##Fixed:

  • #71: EnumSet::setBinaryBitset*(): out-of-range bits of last byte not truncated
  • #77: Missing additional check on Enum::is() to return TRUE in some circumstances

Deprecations:

  • #63 :EnumSet::getBitset() : string
  • #63: EnumSet::setBitset(string $bitset)
  • #79: Enum::clear()
  • #80: Enum::getByName()
  • #80: Enum::getByOrdinal()

BC-breaks:

  • none

https://github.com/marc-mabe/php-enum/milestone/11?closed=1

v2.2.1

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

v2.2.0

Feature release of the 2.x branch.

Changes:

  • #53 Added new method Enum::has()

BC-breaks:

  • none

https://github.com/marc-mabe/php-enum/pulls?utf8=%E2%9C%93&q=is%3Aclosed+milestone%3A2.2.0

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport