tkachikov / enum-values
Set methods for get values and keys from a enum
Installs: 2 590
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
This package is auto-updated.
Last update: 2025-03-05 11:30:12 UTC
README
Description
This PHP package provides a trait EnumValuesTrait
that adds utility methods for working with enumerations (enums).
Installation
To install the package, run the following command:
composer require tkachikov/enum-values
Usage
Include the trait into your enum class:
<?php namespace App\Enums; use Tkachikov\EnumValues\EnumValuesTrait; class StateEnum: int { use EnumValuesTrait; const ACTIVE = 10; const BLOCKED = 20; }
Now you can use the methods getKeys()
, getValues()
, getByKey()
and getByValue()
for interacting with the enum:
$values = StateEnum::getValues(); // [10, 20] $keys = StateEnum::getKeys(); // ['ACTIVE', 'BLOCKED'] $arrayByKey = StateEnum::getByKey(); // ['ACTIVE' => 10, 'BLOCKED' => 20] $arrayByValue = StateEnum::getByValue(); // [10 => 'ACTIVE', 20 => 'BLOCKED']
Author
Alex Tkachikov Email: a.tkachikov@mail.ru
License
MIT