Download the PHP package sypspace/laravel-enum without Composer
On this page you can find all versions of the php package sypspace/laravel-enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sypspace/laravel-enum
More information about sypspace/laravel-enum
Files in sypspace/laravel-enum
Package laravel-enum
Short Description Enum generator for Laravel.
License MIT
Homepage https://github.com/cerbero90/laravel-enum
Informations about the package laravel-enum
Laravel Enum
Laravel package that introduces a new Artisan command to generate Enum classes.
It provides an easy syntax to specify and map constants in Enum classes while adding PHPDoc tags to make IDEs recognise what constants can be invoked as methods to instantiate an Enum class.
Install
Via Composer
Usage
Enums can be generated by calling the Artisan command make:enum
and specifying the class and constant names. Many enums can be defined at once by separating them with pipes (please note the use of quotes):
In the previous example no key has been defined, in this case keys are assumed to be equal to their lowercased constant name. This is how the Status
enum will look like:
Nonetheless you may need to define your own keys, that is possible by pairing constant names and keys with an =
character:
The command above will generate the following Status
enum:
Similarly you can specify enum values by pairing keys and values with an =
character:
The above command will generate the following Status
enum and implement the map()
method:
Sometimes you may want to define array of values in your keys or values, you can do that by providing JSON strings:
This package will take care of building, indenting and formatting the array for you:
You may also generate keys without the need to define them by using the --keys
option:
--keys=bitwise
generates bitwise keys (1, 2, 4, 8...)--keys=int0
generates 0-indexed integer keys (1, 2, 3, 4...)--keys=int1
generates 1-indexed integer keys (0, 1, 2, 3...)--keys=lower
generates keys by converting constant names to lower case
The following paired commands generate the same Enum class:
When --keys
is provided, you may define enum values by pairing names and values with an =
character:
The command above will generate the following JSON
enum:
By default enums are generated in the app/Enums
directory. If you prefer a different location, you can set the option --path
(or the shortcut -p
):
The above command will generate the Status
class in app/Other/Directory
.
If you try to generate an enum that already exists, the existing enum won't be overwritten unless you set the option --force
(or the shortcut -f
):
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please see CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-enum with dependencies
illuminate/console Version ^5.6|^6.0|^7.0|^8.0
illuminate/support Version ^5.6|^6.0|^7.0|^8.0
rexlabs/enum Version ^2.0