utilitte / enum
该包最新版本(v2.0.0)没有提供许可信息。
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-09-13 18:41:41 UTC
README
类型安全的枚举
入门指南
创建枚举类
/** * @method static self ENGLAND() * @method static self USA() */ class CountryEnum extends Enum { protected static function getEnums(): array { return ['england', 'usa']; } }
用法
静态方法必须始终大写
assert(CountryEnum::USA() === CountryEnum::USA()); function country(CountryEnum $country): string { return $country->value(); } assert(country(CountryEnum::USA()) === 'usa');
将枚举值转换为对象
assert(CountryEnum::get('usa') === CountryEnum::USA());