1 | <?php |
||
18 | abstract class BasicEnum |
||
19 | { |
||
20 | //<editor-fold desc="Fields"> |
||
21 | /** @var null|mixed[][] */ |
||
22 | private static $constCacheArray = NULL; |
||
23 | |||
24 | /** @var null|string[][] */ |
||
25 | private static $constCacheArrayCaseMapping = NULL; |
||
26 | |||
27 | /** @var null|string[][] */ |
||
28 | private static $nameArray = NULL; |
||
29 | //</editor-fold desc="Fields"> |
||
30 | |||
31 | //<editor-fold desc="Public Methods"> |
||
32 | /** |
||
33 | * Ensures that the given value is valid by throwing an exception if it is not valid |
||
34 | * @param mixed $value the value to check for validity |
||
35 | * @param bool $strict if yes type checks are performed |
||
36 | * @throws ValueNotValid if the value is not valid |
||
37 | */ |
||
38 | public static function ensureValidValue($value, bool $strict = true): void |
||
44 | |||
45 | /** |
||
46 | * Gets the name of the given value, throwing an exception if the value is not valid |
||
47 | * @param mixed $value the value to get the name for |
||
48 | * @return string the name of the value |
||
49 | * @throws ValueNotValid if the value is not valid |
||
50 | */ |
||
51 | public static function getName($value): string |
||
60 | |||
61 | /** |
||
62 | * Gets a list of all names in this enum |
||
63 | * @return mixed[] |
||
64 | */ |
||
65 | public static function getNames(): array |
||
69 | |||
70 | /** |
||
71 | * Gets the value corresponding to the given name |
||
72 | * @param string $name the name for which to get the value |
||
73 | * @param bool $strict if yes retrieval is done case sensitive and otherwise case insensitive |
||
74 | * @return mixed the corresponding value |
||
75 | * @throws ValueNotValid if the name is not valid |
||
76 | */ |
||
77 | public static function getValue(string $name, bool $strict = false) |
||
94 | |||
95 | /** |
||
96 | * Gets a list of all values in this enum |
||
97 | * @return mixed[] |
||
98 | */ |
||
99 | public static function getValues(): array |
||
103 | |||
104 | /** |
||
105 | * Checks if a given name is part of this enum |
||
106 | * @param string $name the name to check for validity |
||
107 | * @param bool $strict if yes check is done case sensitive and otherwise case insensitive |
||
108 | * @return bool true if the name is part of the enum and false otherwise |
||
109 | */ |
||
110 | public static function isValidName(string $name, bool $strict = false): bool |
||
121 | |||
122 | /** |
||
123 | * Checks if a given value is part of this enum |
||
124 | * @param mixed $value the value to check for validity |
||
125 | * @param bool $strict if yes type checks are performed |
||
126 | * @return bool true if the value is part of the enum and false otherwise |
||
127 | */ |
||
128 | public static function isValidValue($value, bool $strict = true): bool |
||
133 | //</editor-fold desc="Public Methods"> |
||
134 | |||
135 | //<editor-fold desc="Private Methods"> |
||
136 | |||
137 | /** |
||
138 | * Gets a case mapping which maps a lower case names to the real enum names |
||
139 | * @return mixed[] |
||
140 | */ |
||
141 | private static function getCaseMapping(): array |
||
155 | |||
156 | /** @noinspection PhpDocMissingThrowsInspection */ //ReflectionException |
||
157 | /** |
||
158 | * Gets a dictionary of all constants in this enum |
||
159 | * @param string|null $calledClass |
||
160 | * @return mixed[] |
||
161 | */ |
||
162 | private static function getConstants($calledClass = null): array |
||
180 | |||
181 | /** |
||
182 | * Gets a dictionary mapping values to names in this enum |
||
183 | * @param string|null $calledClass |
||
184 | * @return string[] |
||
185 | */ |
||
186 | private static function getNamesArray($calledClass = null): array |
||
199 | //</editor-fold desc="Private Methods"> |
||
200 | } |