Skip to content

Commit

Permalink
chore: Add toLabels() method to LazyEnum trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilan-riviere committed Jun 29, 2024
1 parent 69b9bfa commit bbcaa75
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Traits/LazyEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public static function toValues(): array
return $array;
}

public static function toLabels(): array
{
$array = [];

foreach (static::cases() as $definition) {
if (method_exists($definition, 'getLabel')) {
$array[$definition->name] = $definition->getLabel();
} else {
$array[$definition->name] = $definition->name;
}
}

return $array;
}

public function getLabel(): ?string
{
return $this->name;
Expand Down

0 comments on commit bbcaa75

Please sign in to comment.