sunnyphp / enum
Simple AbstractEnum class
v1.0.1
2021-09-18 17:13 UTC
Requires
- php: ^7.4 || ^8
Requires (Dev)
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2025-03-19 00:53:01 UTC
README
Installation
composer require sunnyphp/enum
Usage
use SunnyPHP\Enum\AbstractEnum; class MyEnum extends AbstractEnum { public const HELLO = 1; public const WORLD = 2; }
Methods
Method name | Description | Example | Returns |
---|---|---|---|
get |
Returns constant value if exists or default value (42) if not exists | MyEnum::get('HELLO', 42) |
1 |
getValues |
Returns all constant values | MyEnum::getValues() |
[1, 2, ] |
getKeys |
Returns all keys (constant names) | MyEnum::getKeys() |
['HELLO', 'WORLD', ] |
getAll |
Returns all constants, key-value pairs | MyEnum::getAll() |
['HELLO' => 1, 'WORLD' => 2, ] |
hasValue |
Returns True if constant value is exists | MyEnum::hasValue(1) |
true |
hasKey |
Returns True if constant is exists | MyEnum::hasKey('HELLO') |
true |
hasAnyKey |
Returns True if one or more constants is exists | MyEnum::hasAnyKey('FOO', 'HELLO', 'BAR') |
true |