pkly / enum-attribute-utils
Helper for easy attribute load/cache/fetch etc. in PHP Enums
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/pkly/enum-attribute-utils
Requires
- php: >=8.4
Requires (Dev)
This package is auto-updated.
Last update: 2026-01-27 11:17:30 UTC
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); } }
See the trait for more methods.
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.