| Arrayable | Closure */ protected array | Arrayable | Closure $descriptions = []; /** * @param array | Arrayable | Closure $descriptions */ public function descriptions(array | Arrayable | Closure $descriptions): static { $this->descriptions = $descriptions; return $this; } /** * @param array-key $value */ public function hasDescription($value): bool { return array_key_exists($value, $this->getDescriptions()); } /** * @param array-key $value */ public function getDescription($value): string | Htmlable | null { return $this->getDescriptions()[$value] ?? null; } /** * @return array */ public function getDescriptions(): array { $descriptions = $this->evaluate($this->descriptions); if ($descriptions instanceof Arrayable) { $descriptions = $descriptions->toArray(); } if ( empty($descriptions) && is_string($this->options) && enum_exists($this->options) && is_a($this->options, HasDescription::class, allow_string: true) ) { $descriptions = array_reduce($this->options::cases(), function (array $carry, HasDescription & UnitEnum $case): array { if (filled($description = $case->getDescription())) { $carry[$case?->value ?? $case->name] = $description; } return $carry; }, []); } return $descriptions; } }