Download the PHP package azimkordpour/power-enum without Composer
On this page you can find all versions of the php package azimkordpour/power-enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download azimkordpour/power-enum
More information about azimkordpour/power-enum
Files in azimkordpour/power-enum
Package power-enum
Short Description This light package provides some methods to your Enum classes to make the most of them.
License MIT
Informations about the package power-enum
Power Enum Classes in PHP
This lightweight package provides a Trait
that allows you to fully utilize Enum classes in your PHP projects, particularly in modern PHP frameworks like Laravel
.
Installation
NOTE: As Enum was introduced in PHP 8.1, this package requires a minimum PHP version of 8.1.
You can install the package via composer:
Usage Instructions
To use the PowerEnum
trait in your Enum class, simply import it like this:
Now, let's take a closer look at the methods.
In Laravel
Eloquent allows you to cast your attribute values to PHP Enums.
Then, you can use it like the below examples.
Check if the status of the model is active
:
Returns boolean:
Check if the status of the model equals the given value:
Returns boolean:
This method works like equals
:
Returns boolean:
Get the label of the status:
Returns the value of the case if you have not set labels:
For setting custom labels and Seeing all methods in PHP projects, take a look at the next section.
All Methods
Get the values of PostStatus
statically:
Returns an array:
Get the names of PostStatus
statically:
Returns an array:
Get the names and values of PostStatus
statically:
Returns an array:
Check if the case is the active one:
Returns boolean:
Check if the case equals the given value:
Returns boolean:
This method works like equals
:
Returns boolean:
Initiate the class from name:
Returns the Enum object:
Get the label of the case:
Returns the value of the case if you have not set labels:
Get the labels of the cases:
Returns the values of the cases if you have not set labels:
You can write custom label for the cases in your Enum class:
Then, the method of label
:
Returns:
And the method of getLabels
:
Returns: