| @@ 74-83 (lines=10) @@ | ||
| 71 | * |
|
| 72 | * @return $this The new type instance |
|
| 73 | */ |
|
| 74 | public static function createByName($name) |
|
| 75 | { |
|
| 76 | $constants = static::getConstantsByName(); |
|
| 77 | ||
| 78 | if (!array_key_exists($name, $constants)) { |
|
| 79 | throw new UnexpectedValueException("Name '{$name}' is not exists in the enum constants list " . get_called_class()); |
|
| 80 | } |
|
| 81 | ||
| 82 | return new static($constants[$name]); |
|
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * get constant key by value(label) |
|
| @@ 236-245 (lines=10) @@ | ||
| 233 | * |
|
| 234 | * @throws BadMethodCallException |
|
| 235 | */ |
|
| 236 | public static function __callStatic($name, $arguments) |
|
| 237 | { |
|
| 238 | $constants = static::getConstantsByName(); |
|
| 239 | ||
| 240 | if (isset($constants[$name])) { |
|
| 241 | return new static($constants[$name]); |
|
| 242 | } |
|
| 243 | ||
| 244 | throw new BadMethodCallException("No static method or enum constant '$name' in class " . get_called_class()); |
|
| 245 | } |
|
| 246 | ||
| 247 | /** |
|
| 248 | * @return string |
|