Skip to content

henzeb/enumhancer

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date
Mar 2, 2022
Mar 2, 2022
Mar 2, 2022
Feb 15, 2022
Feb 15, 2022
Feb 15, 2022
Feb 15, 2022
Feb 15, 2022
Mar 2, 2022
Feb 15, 2022
Feb 15, 2022
Mar 2, 2022
Feb 15, 2022

Repository files navigation

Enumhancer

Latest Version on Packagist Total Downloads

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

Installation

You can install the package via composer:

composer require henzeb/enumhancer

Usage

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.

Functionality

Laravel

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"
            ]
        }
    }

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The GNU AGPLv. Please see License File for more information.