zyimm / php-constants
There is no license information available for the latest version (0.0.3) of this package.
php项目枚举常量配置管理&调用包
0.0.3
2024-01-03 01:56 UTC
Requires
- php: >=7.0
README
安装
composer require zyimm/php-constants
使用示例
以一个简单流程配置为例:
class FlowConst extends \Zyimm\PhpConstants\Constants { protected static array $status = [ 'wait' => [ 'value' => 0, 'title' => '待审核' ], 'pass' => [ 'value' => 1, 'title' => '通过' ], 'reject' => [ 'value' => 2, 'title' => '拒绝' ], 'cancel' => [ 'value' => 3, 'title' => '已取消' ] ]; }
1.获取某个枚举数值
FlowConst::getValueByKey('wait', 'status'); // 1 FlowConst::getValueByKey('cancel', 'status'); // 0
2.获取枚举数值map
FlowConst::getMap('status');// [0=>'待审核', 1=> '通过' ....]
3.map转list
FlowConst::getMapList('status'); /** * [ * [ * 'value' => 0, * 'title' => '待审核' * ], * [ * 'value' => 1, * 'title' => '通过' * ] * * ] * * */