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

myclabs/php-enum

myclabs/php-enum brings SplEnum-style enums to PHP. Define enum classes, get autogenerated static constructors, validate values, compare instances, list possible values, and use enums as parameter/return types with extra methods—without a PHP extension.

View on GitHub
Deep Wiki
Context7
1.8.5

What's Changed

New Contributors

Full Changelog: https://github.com/myclabs/php-enum/compare/1.8.4...1.8.5

1.8.4

What's Changed

New Contributors

Full Changelog: https://github.com/myclabs/php-enum/compare/1.8.3...1.8.4

1.8.3

#147 Fix Psalm annotation

1.8.2

#146 Fix Psalm annotation

1.8.1

Resolve deprecation on PHP 8.1 #145

1.8.0

Added:

  • new Enum::from() method as an alternative to the constructor that is more strictly typed, and provides a forward compatible solution with PHP 8.1 enums
  • new Enum::assertValidValue() to assert that a value is correct

Psalm annotations have been improved as well.

Thanks @drealecs, @Ocramius, @michaelpetri, @gharlan, @simPod

1.7.7

#129 Performance improvement

1.7.6

Avoid conflicts with Doctrine Annotations by renaming the Psalm [@template](https://github.com/template) annotation into [@psalm-template](https://github.com/psalm-template).

1.7.5

#112 Improved Psalm typing

1.7.4

Psalm has been moved to require-dev ;)

1.7.3

#111 Add Psalm annotations

1.7.2

Fixed #95 with #97: handle inherited enums

1.7.1
  • Compatibility with PHP 7.1
  • #90 New PHPUnit comparator to help with tests
1.7.0
  • #88: require PHP 7.2 + add a return type to the equals() method
  • #87: the equals() method now accepts anything as a parameter
  • #86: compatibility with php-ds/ext-ds
1.6.6

#84 Require ext-json explicitly in composer.json to avoid bugs when the JSON extension is not installed

1.6.5

#83: It is now possible to create a new Enum instance from another Enum instance

1.6.4

#80 Fix validating key with null value #82 Fix coding style and setup https://prettyci.com

1.6.3

Fix #77 #78: better support for null values in enums.

1.6.2

#75 Performance optimizations

1.6.1

#71 Allow null in the equals() method

1.6.0
  • Drop support for PHP 5.3 (only 5.4+ is supported)
  • Implement JsonSerializable interface to allow serializing the class to JSON
1.5.2

Remove unneeded file permissions.

1.5.1

Bugfix in the equals() method

Issue: #47 Pull request: #48 Contributed by @peter-gribanov

Example:

class CommandAction extends Enum
{
    const EDIT = 'edit';
}

class AccessRule extends Enum
{
    const EDIT = 'edit';
}

Expected

CommandAction::EDIT()->equals(AccessRule::EDIT()); // false

Actual

CommandAction::EDIT()->equals(AccessRule::EDIT()); // true
1.5.0

#4 #39 #40: new equals() method to compare enums

$enum = MyEnum::FOO();

if ($enum->equals(MyEnum::BAR())) {
    ...
}

It behaves the same as ==:

if ($enum == MyEnum::BAR()) {
    ...
}

It was added because it carries a bit more sense than == which, because it is a loose comparison, is often source of confusion (comparing objects with == is often a no-go for good reasons).

1.4.2
  • #36, #37 Small phpdoc improvement for better autocompletion in IDEs
1.4.1

#21 Allow to extend the class to fetch values from somewhere else than the class constants (e.g. a database, file, …)

1.4.0

New static method values(): returns instances of the Enum class of all Enum constants (constant name in key, Enum instance in value).

MyEnum::values()

1.3.2
  • Fixed #9 Ability to create invalid enum
  • Fixed #13 search() is not type safe
1.3.1

Small performance enhancement.

1.3.0

A bunch of new methods were added in #5:

  • $value->getKey() Returns the key of the current value on Enum
  • Enum::keys() Returns the names (keys) of all constants in the Enum class
  • Enum::isValid() Check if tested value is valid on enum set
  • Enum::isValidKey() Check if tested key is valid on enum set
  • Enum::search() Return key for searched value

The library is now PSR-4 compliant.

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