1 | <?php |
||
21 | abstract class AbstractEnum |
||
22 | { |
||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected static $cache = []; |
||
27 | |||
28 | /** |
||
29 | * Return all constants as Key => Value array. |
||
30 | * |
||
31 | * @return array |
||
32 | */ |
||
33 | 366 | public static function toArray(): array |
|
43 | |||
44 | /** |
||
45 | * Return all constants Keys as array. |
||
46 | * |
||
47 | * @return array|string[] |
||
48 | */ |
||
49 | 52 | public static function getKeys(): array |
|
53 | |||
54 | /** |
||
55 | * Return Enum Key for requested Value. |
||
56 | * |
||
57 | * @param string $value |
||
58 | * |
||
59 | * @throws \InvalidArgumentException |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | 26 | public static function getKey(string $value): string |
|
69 | |||
70 | /** |
||
71 | * Validate if Key is valid. |
||
72 | * |
||
73 | * @param string $key |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | 104 | public static function isValidKey(string $key): bool |
|
81 | |||
82 | /** |
||
83 | * Throw exception if Key is not valid. |
||
84 | * |
||
85 | * @param string $key |
||
86 | * |
||
87 | * @throws \InvalidArgumentException |
||
88 | */ |
||
89 | 104 | public static function assertIsValidKey(string $key): void |
|
95 | |||
96 | /** |
||
97 | * Return Enum Value for requested Key. |
||
98 | * |
||
99 | * @param string $key |
||
100 | * |
||
101 | * @throws \InvalidArgumentException |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | 26 | public static function getValue(string $key): string |
|
111 | |||
112 | /** |
||
113 | * Return all constants Values as array. |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | 52 | public static function getValues(): array |
|
121 | |||
122 | /** |
||
123 | * Validate if Value is valid. |
||
124 | * |
||
125 | * @param string $value |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | 184 | public static function isValidValue(string $value): bool |
|
133 | |||
134 | /** |
||
135 | * Throw exception if Value is not valid. |
||
136 | * |
||
137 | * @param string $value |
||
138 | * |
||
139 | * @throws \InvalidArgumentException |
||
140 | */ |
||
141 | 184 | public static function assertIsValidValue(string $value): void |
|
147 | } |
||
148 |