pkly/enum-attribute-utils
Composer 安装命令:
composer require pkly/enum-attribute-utils
包简介
Helper for easy attribute load/cache/fetch etc. in PHP Enums
README 文档
README
Helper for easy attribute load/cache/fetch etc. in PHP Enums
Installation
Simply run
composer require pkly/enum-attribute-utils
Usage
Example use on an enum.
use Pkly\EnumAttributeUtils\AttributeControlTrait; enum ExampleEnum { use AttributeControlTrait; #[NotAllowed] case Foo; #[CustomStuff(true)] case Bar; /** * @return list<self> */ public static function getNotAllowed(): array { return self::findCases(NotAllowed::class); } public function isNotAllowed(): bool { return self::attributeExists(NotAllowed::class, $this); } public function getCustom(): CustomStuff|null { return self::findAttribute(CustomStuff::class, $this); } public function getCustomWithTrue(): CustomStuff|null { return self::findAttribute(CustomStuff::class, $this, static fn (CustomStuff $s) => $s->thing); } }
See the trait for more methods.
You can use the $filter parameter to better revise results, so that you don't have to create multiple classes to gain the same functionality.
Attributes are preloaded once per enum and stored in AttributeCache.
It's not suggested to touch said class, it's required as enums cannot contain properties.
统计信息
- 总下载量: 303
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-27