In this library you'll find some of the most common use-cases for enums. If you find yourself recreating functionalities, maybe this package is something for you.
This package currently supports the following:
- Constructor (in case you're migrating from Spatie's PHP Enum)
- Comparison
- From (for unit enums)
- Make (Ability to make from enum-name)
- Labels
- Mappers
- Multi
- Properties
- Reporting (Logging)
- Value
You can install the package via composer:
composer require henzeb/enumhancer
You can simply add the Enhancers
trait to your enum
in
order to use almost all functionality of this package. All functionality
should work with unit
enums as well as backed
enums'.
use Henzeb\Enumhancer\Concerns\Enhancers\Enhancers;
enum YourEnum {
use Enhancers;
// ...
}
You can also just use one of the functionalities by using the specific trait for that functionality.
Note: all traits can be used next to each other, except for Mappers
, which has
implemented his own version of Makers
and Reporters
.
When you are installing this package into a laravel project, Enumhancer will
automatically set the global Reporter
for the makeOrReport
methods, so that
it will use Laravel's Log
facade.
If you don't want that to happen, you can tell Laravel not to discover the package.
"extra": {
"laravel": {
"dont-discover": [
"henzeb/enumhancer"
]
}
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The GNU AGPLv. Please see License File for more information.