Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zyimm/php-constants
php项目枚举常量配置管理&调用包
https://github.com/zyimm/php-constants
Last synced: 11 days ago
JSON representation
php项目枚举常量配置管理&调用包
- Host: GitHub
- URL: https://github.com/zyimm/php-constants
- Owner: zyimm
- License: mit
- Created: 2023-07-27T03:49:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-03T01:56:27.000Z (11 months ago)
- Last Synced: 2024-10-12T06:44:57.842Z (about 1 month ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php项目枚举常量配置管理&调用包
安装
```shell
composer require zyimm/php-constants
```## 使用示例
以一个简单流程配置为例:
```php
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.获取某个枚举数值
```php
FlowConst::getValueByKey('wait', 'status'); // 1
FlowConst::getValueByKey('cancel', 'status'); // 0
```2.获取枚举数值map
```php
FlowConst::getMap('status');// [0=>'待审核', 1=> '通过' ....]
```3.map转list
```php
FlowConst::getMapList('status');
/**
* [
* [
* 'value' => 0,
* 'title' => '待审核'
* ],
* [
* 'value' => 1,
* 'title' => '通过'
* ]
*
* ]
*
*
*/
```