1 | <?php |
||
24 | abstract class Enum implements EquatableInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var mixed |
||
28 | */ |
||
29 | protected $value; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected static $cache = array(); |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected static $defaultCache = array(); |
||
40 | |||
41 | /** |
||
42 | * @param string $name |
||
43 | * @param array $arguments |
||
44 | * |
||
45 | * @return static |
||
46 | * |
||
47 | * @throws \BadMethodCallException |
||
48 | */ |
||
49 | public static function __callStatic($name, $arguments) |
||
64 | |||
65 | /** |
||
66 | * Creates a new value of some type. |
||
67 | * |
||
68 | * @param mixed $value |
||
69 | * |
||
70 | * @throws \UnexpectedValueException if incompatible type is given. |
||
71 | */ |
||
72 | public function __construct($value) |
||
82 | |||
83 | /** |
||
84 | * @return mixed |
||
85 | */ |
||
86 | public function value() |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | public function name() |
||
98 | |||
99 | /** |
||
100 | * @param mixed $value |
||
101 | * |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function is($value) |
||
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | public function equals($other) |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function hashCode() |
||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | public function __toString() |
||
132 | |||
133 | /** |
||
134 | * @param $value |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | public static function isValid($value) |
||
142 | |||
143 | /** |
||
144 | * @param $name |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | public static function isValidName($name) |
||
154 | |||
155 | /** |
||
156 | * @return array |
||
157 | */ |
||
158 | public static function names() |
||
162 | |||
163 | /** |
||
164 | * @return static[] |
||
165 | */ |
||
166 | public static function values() |
||
175 | |||
176 | /** |
||
177 | * @return array |
||
178 | */ |
||
179 | public static function toArray() |
||
190 | |||
191 | /** |
||
192 | * @param Enum $enum |
||
193 | * @param Enum $default |
||
194 | * |
||
195 | * @throws \InvalidArgumentException |
||
196 | * |
||
197 | * @return static |
||
198 | */ |
||
199 | public static function ensure(Enum $enum = null, Enum $default = null) |
||
210 | |||
211 | /** |
||
212 | * @param $value |
||
213 | * |
||
214 | * @return mixed |
||
215 | */ |
||
216 | protected static function search($value) |
||
220 | |||
221 | /** |
||
222 | * @param string $class |
||
223 | * |
||
224 | * @return array |
||
225 | */ |
||
226 | private static function constants($class) |
||
239 | } |
||
240 |