tuscanicz/enum
最新稳定版本:v2.1
Composer 安装命令:
composer require tuscanicz/enum
包简介
PHP implementation of Enum with strict comparisons
关键字:
README 文档
README
PHP implementation of Enum with strict comparisons
<?php use Enum\AbstractEnum; class Day extends AbstractEnum { const SUNDAY = 0; const MONDAY = 1; const TUESDAY = 2; const WEDNESDAY = 3; const THURSDAY = 4; const FRIDAY = 5; const SATURDAY = 6; protected static $default = self::SUNDAY; public function getLabel() { return date('l', strtotime(sprintf('Sunday + %d Days', $this->getValue()))); } } $defaultDay = new Day(); echo $defaultDay->getValue(); // 0 echo $defaultDay->getLabel(); // Sunday $monday = new Day(Day::MONDAY); echo $monday->getValue(); // 1 echo $monday; // 1 print_r(Day::getValues()); // Array ( [SUNDAY] => 0 [MONDAY] => 1 [TUESDAY] => 2 [WEDNESDAY] => 3 [THURSDAY] => 4 [FRIDAY] => 5 [SATURDAY] => 6 ) echo $monday->getLabel(); // Monday print_r(Day::getLabels()); // Array ( [0] => Sunday [1] => Monday [2] => Tuesday [3] => Wednesday [4] => Thursday [5] => Friday [6] => Saturday )
Contribute
Feel free to contribute!
Please, run the tests via phpunit php vendor/phpunit/phpunit/phpunit and keep the code coverage.
统计信息
- 总下载量: 291.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-22