- EnumUtilsTrait (core) → 2. EnumCollection → 3. Validation → 4. Laravel Integration → 5. Doctrine Integration
The main trait for BackedEnum. All methods are static.
cases()— already provided by PHPvalues(): array— return all backing valueslabels(): array— return [value => label] maptoSelectArray(): array— alias for labels(), returns [value => label]toRadioOptions(): array— returns array of {value, label, name} objectsfromLabel(string): static— find case by label, throw on misstryFromLabel(string): ?static— find case by label, null on missrandomCase(): static— random casetoJsonValue(): string|int— instance method, returns backing valuefromJsonValue(string|int): static— static, wraps from()- Label resolution: if enum has
label(): stringmethod, use it; otherwise humanize case name (SCREAMING_SNAKE → Title Case)
Wraps an array of enum cases with collection operations.
__construct(array $cases)filter(callable): selfmap(callable): arraycontains(BackedEnum): booldiff(self): selftoArray(): arraycount(): int(Countable)- Static
from(string $enumClass): self— creates collection of all cases
Interface: Contracts\HasLabels with label(): string method.
Standalone validation rule (no framework dependency).
__construct(string $enumClass)validate(mixed $value): boolmessage(): string
Kexxt\EnumUtils\Integration\Laravel\EnumCast- Implements
CastsAttributes(interface check only, no Laravel dependency) get()/set()methods usingfrom()/->value
Kexxt\EnumUtils\Integration\Doctrine\AbstractEnumType- Abstract class users extend per enum
convertToPHPValue()/convertToDatabaseValue()
- Zero runtime dependencies: Framework integrations reference interfaces by string, no imports
- Label convention: humanize SCREAMING_SNAKE case names as default
- PHPStan level 9: Use generics/templates where needed for type safety
- Trait over base class: PHP enums can't extend classes, trait is the only option
All public methods on EnumUtilsTrait:
static values(): array<int, string|int>
static labels(): array<string|int, string>
static toSelectArray(): array<string|int, string>
static toRadioOptions(): array<int, array{value: string|int, label: string, name: string}>
static fromLabel(string $label): static
static tryFromLabel(string $label): ?static
static randomCase(): static
static fromJsonValue(string|int $value): static
toJsonValue(): string|int
static collect(): EnumCollection