21 abstract class Enum implements \JsonSerializable
38 protected static $cache = [];
51 if (
$value instanceof
static) {
58 throw new \UnexpectedValueException(
"Value '$value' is not part of the enum " . static::class);
83 return static::search($this->value);
106 final public function equals($variable =
null): bool
108 return $variable instanceof
self
110 && static::class === \get_class($variable);
120 public static function keys()
122 return \array_keys(static::toArray());
132 public static function values()
137 foreach (static::toArray() as $key =>
$value) {
138 $values[$key] =
new static(
$value);
153 public static function toArray()
155 $class = static::class;
157 if (!isset(static::$cache[$class])) {
158 $reflection = new \ReflectionClass($class);
159 static::$cache[$class] = $reflection->getConstants();
162 return static::$cache[$class];
175 return \in_array(
$value, static::toArray(),
true);
188 $array = static::toArray();
190 return isset($array[$key]) || \array_key_exists($key, $array);
204 return \array_search(
$value, static::toArray(),
true);
219 $array = static::toArray();
220 if (isset($array[$name]) || \array_key_exists($name, $array)) {
221 return new static($array[$name]);
224 throw new \BadMethodCallException(
"No static method or enum constant '$name' in class " . static::class);