skinka / type-enum
简单快速的枚举实现,支持PHP 5.4及以上版本
1.0.3
2016-07-30 20:48 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-14 19:19:55 UTC
README
这是一个抽象类,需要扩展后才能使用枚举。
什么是枚举? #安装 将 skinka/type-enum
添加到项目的 composer.json 依赖项中,然后运行 php composer.phar install
#用法 ##创建枚举
<?php namespace skinka\php\TypeEnum\enums; use skinka\php\TypeEnum\BaseEnum; /** * Class to enumerations of YES or NO status * * @method static YesNo YES() * @method static YesNo NO() * @method string text() */ class YesNo extends BaseEnum { const YES = 1; const NO = 0; public static function getData() { return [ self::YES => [ 'text' => 'Yes', ], self::NO => [ 'text' => 'No', ] ]; } }
##使用枚举示例
YesNo::getDataList(); //[0 => 'No', 1 => 'Yes'] YesNo::getKeys(); //[0,1] YesNo::NO(); //0 YesNo::YES()->text(); //Yes YesNo::YES()->getValue(); //1 YesNo::YES()->getArray(); //['text' => 'Yes'] YesNo::getByValue(0)->text(); //No YesNo::getByName('YES'); //1