chadsikorra/php-simple-enum
最新稳定版本:1.0.0
Composer 安装命令:
composer require chadsikorra/php-simple-enum
包简介
Provides a simple enum and flag enum for PHP.
关键字:
README 文档
README
Provides a simple enum and flag enum for PHP using traits and interfaces.
A simple enum example:
use Enums\SimpleEnumInterface; use Enums\SimpleEnumTrait; class DayOfWeek implements SimpleEnumInterface { use SimpleEnumTrait; const Monday = 1; const Tuesday = 2; const Wednesday = 3; const Thursday = 4; const Friday = 5; const Saturday = 6; const Sunday = 7; } // Get all of the names var_dump(DayOfWeek::names()); // Get all of the values var_dump(DayOfWeek::values()); // View it as an array var_dump(DayOfWeek::toArray()); // Check if a name is valid. This is case insensitive. if (DayOfWeek::isValidName('Monday')) { // ... } // Check if a value is valid. if (DayOfWeek::isValidValue(DayOfWeek::Monday)) { // ... } // Get the name for a specific value. var_dump(DayOfWeek::getValueName(1)); // Get the value for a specific name. This is case insensitive. var_dump(DayOfWeek::getNameValue('Monday'));
A flag enum example:
use Enums\FlagEnumInterface; use Enums\FlagEnumTrait; class FilePermission implements FlagEnumInterface { use FlagEnumTrait; const Read = 1; const Write = 2; const Execute = 4; } $permission = new FilePermission(FilePermission::Read | FilePermission::Write); // Remove a permission $permission->remove('Write'); // Add a permission $permission->add('Execute'); // Check for a permission if ($permission->has('Read')) { // ... } // Get the flag value var_dump($permission->getValue()); // Get all of the names for the flag as an array var_dump($permission->getNames()); // View the string representation (comma delimited list) var_dump((string) $permission);
The static methods are available in both the simple and flag enums.
统计信息
- 总下载量: 288.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-28