legecha/enumpty
Composer 安装命令:
composer require legecha/enumpty
包简介
Find yourself creating methods like label(), description() or icon() on your enums? This very simple package takes the legwork out of doing so for you, and gives you the same functionality without implementing the methods.
README 文档
README
Describe your enums!
Find yourself creating methods like label(), description() or icon() on your enums? This very simple package takes the legwork out of doing so for you, and gives you the same functionality without implementing the methods.
Instead, just describe your cases with attributes!
Example
Simply use the Describable trait and describe your cases with the DescribeEnum attribute using named parameters.
Methods on the enum values are now available, as well as static *Cases methods on the enum type.
use Legecha\Enumpty\Attributes\DescribeEnum; use Legecha\Enumpty\Describable; enum MyEnum { use Describable; #[DescribeEnum(label: 'My First Case', description: "My first description")] case First; #[DescribeEnum(description: "My second description", label: 'My 2nd Case']) case Second; case Third; #[DescribeEnum(label: 'My Fourth Case')] case Fourth; } $enum = MyEnum::First; $enum->label(); // string(13) "My First Case" $enum->description(); // string(20) "My first description" $enum = MyEnum::Third; $enum->description(); // NULL MyEnum::labelCases(); /* array(4) { ["MyEnum::First"]=> string(13) "My First Case" ["MyEnum::Second"]=> string(11) "My 2nd Case" ["MyEnum::Third"]=> NULL ["MyEnum::Fourth"]=> string(14) "My Fourth Case" } */ MyEnum::descriptionCases(); /* array(4) { ["MyEnum::First"]=> string(20) "My first description" ["MyEnum::Second"]=> string(21) "My second description" ["MyEnum::Third"]=> NULL ["MyEnum::Fourth"]=> NULL } */
But wait, there's more!
There is also the Names trait, which provides a name() method to get a "pretty" version of your enum case's name, and a names() static method to retrieve them all for a specific enum. No attributes required.
use Legecha\Enumpty\Names; enum MyEnum { use Names; case MyFirstCase; case Second; case HereIsTheThird; case DontForgetTheFourth; } $enum = MyEnum::MyFirstCase; $enum->name(); // string(13) "My First Case" MyEnum::HereIsTheThird->name(); // string (15) "Here Is The Third" MyEnum::names(); /* array(4) { ["MyEnum::MyFirstCase"]=> string(13) "My First Case" ["MyEnum::Second"]=> string(6) "Second" ["MyEnum::HereIsTheThird"]=> string(15) "Here Is The Third" ["MyEnum::DontForGetTheFourth"]=> string(23) "Dont Forget The Fourth" } */
Install
composer require legecha/enumpty
Issues and Contributing
This is a very simple package, but pull requests are more than welcome. Please include a test and clean up the code before doing do.
composer test
composer fix
legecha/enumpty 适用场景与选型建议
legecha/enumpty 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 288 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 legecha/enumpty 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 legecha/enumpty 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 288
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-13