Skip to content

Commit 54c2bd9

Browse files
authored
Add HasEnumValue::options() and HasEnumValue::name() (#89)
1 parent 210e0d3 commit 54c2bd9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Objects/Support/Traits/HasEnumValue.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ public static function from(int|string $value): ?static
5555
return null;
5656
}
5757

58+
public static function options(): array
59+
{
60+
$options = [];
61+
62+
foreach (self::cases() as $case) {
63+
$options[$case->value] = self::name($case);
64+
}
65+
66+
return $options;
67+
}
68+
69+
public static function name(self $self): string
70+
{
71+
return $self->name;
72+
}
73+
5874
private static function enforceEnum(): void
5975
{
6076
if (!method_exists(static::class, "cases")) {

0 commit comments

Comments
 (0)