warengo / enum
There is no license information available for the latest version (v2.0.0) of this package.
v2.0.0
2020-10-13 10:03 UTC
Requires
- php: >=7.4
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.0.0
- codeception/module-phpbrowser: ^1.0.0
This package is auto-updated.
Last update: 2024-12-13 19:43:23 UTC
README
Type safe enums
Getting started
Create enum class
/** * @method static self ENGLAND() * @method static self USA() */ class CountryEnum extends Enum { protected static function getEnums(): array { return ['england', 'usa']; } }
Usage
static method must be always uppercase
assert(CountryEnum::USA() === CountryEnum::USA()); function country(CountryEnum $country): string { return $country->value(); } assert(country(CountryEnum::USA()) === 'usa');
convert enum value to object:
assert(CountryEnum::get('usa') === CountryEnum::USA());