1 | <?php |
||
17 | abstract class Enum implements EnumInterface, \Serializable |
||
18 | { |
||
19 | /** |
||
20 | * Cached array of enum instances by enum type (FQCN). |
||
21 | * This cache is used in order to make single enums values act as singletons. |
||
22 | * This means you'll always get the exact same instance for a same enum value. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | private static $instances; |
||
27 | |||
28 | /** @var mixed */ |
||
29 | protected $value; |
||
30 | |||
31 | /** |
||
32 | * The constructor is private and cannot be overridden: use the static get method instead. |
||
33 | * |
||
34 | * @param mixed $value The raw value of an enumeration |
||
35 | 9 | */ |
|
36 | final private function __construct($value) |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | * |
||
59 | * @return static The enum instance for given value |
||
60 | 69 | */ |
|
61 | public static function get($value): EnumInterface |
||
74 | 9 | ||
75 | /** |
||
76 | * Instantiates a new enumeration. |
||
77 | * |
||
78 | * @param string $name The name of a particular enumerated constant |
||
79 | * @param array $arguments |
||
80 | * |
||
81 | * @throws \BadMethodCallException On invalid constant name |
||
82 | * |
||
83 | * @return static When $name is an existing constant for this enumeration type |
||
84 | */ |
||
85 | public static function __callStatic($name, $arguments = []): EnumInterface |
||
98 | 1 | ||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | public static function accepts($value): bool |
||
106 | 19 | ||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | public static function instances(): array |
||
116 | 19 | ||
117 | private static function getCachedInstance($value) |
||
124 | 40 | ||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | public function getValue() |
||
132 | 2 | ||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | public function equals(EnumInterface $enum): bool |
||
140 | 3 | ||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function is($value): bool |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | * @throws NotSerializableException When Enum value type is neither "string" not "int" |
||
152 | */ |
||
153 | public function serialize(): string |
||
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | public function unserialize($serialized) |
||
178 | } |
||
179 |