1 | <?php |
||
2 | |||
3 | namespace Stadem\VivaPayments\Enums; |
||
4 | |||
5 | enum RequestLang: string |
||
6 | { |
||
7 | case Greek = 'el-GR'; |
||
8 | case Bulgarian = 'bg-BG'; |
||
9 | case Croatian = 'hr-HR'; |
||
10 | case Czech = 'cs-CZ'; |
||
11 | case Danish = 'da-DK'; |
||
12 | case Dutch_Netherlands = 'nl-NL'; |
||
13 | case Dutch_Belgium = 'nl-BE'; |
||
14 | case English_UK = 'en-GB'; |
||
15 | case English_US = 'en-US'; |
||
16 | case Finnish = 'fi-FI'; |
||
17 | case French_Belgium = 'fr-BE'; |
||
18 | case French = 'fr-FR'; |
||
19 | case German = 'de-DE'; |
||
20 | case Hungarian = 'hu-HU'; |
||
21 | case Italian = 'it-IT'; |
||
22 | case Polish = 'pl-PL'; |
||
23 | case Portuguese = 'pt-PT'; |
||
24 | case Romanian = 'ro-RO'; |
||
25 | case Russian = 'ru-RU'; |
||
26 | case Spanish = 'es-ES'; |
||
27 | case Swedish = 'sv-SE'; |
||
28 | |||
29 | |||
30 | public static function fromName(string $name): string |
||
31 | { |
||
32 | foreach (self::cases() as $status) { |
||
33 | if( $name === $status->name ){ |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
34 | return $status->value; |
||
35 | } |
||
36 | } |
||
37 | throw new \ValueError("$name is not a valid backing value for enum " . self::class ); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Return value as string |
||
42 | * Enums\RequestLang::fromValue('el-GR'); |
||
43 | */ |
||
44 | |||
45 | public static function fromValue(string $value): string |
||
46 | { |
||
47 | foreach (self::cases() as $status) { |
||
48 | if( $value === $status->value ){ |
||
49 | return $status->name; |
||
0 ignored issues
–
show
|
|||
50 | } |
||
51 | } |
||
52 | throw new \ValueError("$value is not a valid backing value for enum " . self::class ); |
||
53 | } |
||
54 | |||
55 | } |