Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/res/parsecsv/src/enums/AbstractEnum.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace ParseCsv\enums;
4 +
5 + abstract class AbstractEnum {
6 +
7 + /**
8 + * Creates a new value of some type
9 + *
10 + * @param mixed $value
11 + *
12 + * @throws \UnexpectedValueException if incompatible type is given.
13 + */
14 + public function __construct($value) {
15 + if (!$this->isValid($value)) {
16 + throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class());
17 + }
18 + $this->value = $value;
19 + }
20 +
21 + public static function getConstants() {
22 + $class = get_called_class();
23 + $reflection = new \ReflectionClass($class);
24 +
25 + return $reflection->getConstants();
26 + }
27 +
28 + /**
29 + * Check if enum value is valid
30 + *
31 + * @param $value
32 + *
33 + * @return bool
34 + */
35 + public static function isValid($value) {
36 + return in_array($value, static::getConstants(), true);
37 + }
38 + }
39 +