1 | <?php |
||
18 | abstract class AbstractEnum implements EnumInterface, IteratorAggregate |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $value; |
||
24 | |||
25 | /** |
||
26 | * Constructor |
||
27 | * |
||
28 | * @param string $value |
||
29 | */ |
||
30 | public function __construct($value) |
||
38 | |||
39 | /** |
||
40 | * Return the value as a string |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function __toString() |
||
48 | |||
49 | /** |
||
50 | * Do a comparison to check if the enums are non-strictly equal |
||
51 | * |
||
52 | * @param AbstractEnum|string $value |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function equals($value) |
||
63 | |||
64 | /** |
||
65 | * Create a new instance of the enum |
||
66 | * |
||
67 | * @param string $value |
||
68 | * @return $this |
||
69 | */ |
||
70 | public static function create($value) |
||
74 | |||
75 | /** |
||
76 | * Return true if the value is valid for the enum |
||
77 | * |
||
78 | * @param string $value |
||
79 | * @return bool |
||
80 | */ |
||
81 | public static function exists($value) |
||
85 | |||
86 | /** |
||
87 | * Get an array of the enum values |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | public static function values() |
||
95 | |||
96 | /** |
||
97 | * Return enum as an array with keys matching values |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public static function toArray() |
||
105 | |||
106 | /** |
||
107 | * Get the current enum value |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getValue() |
||
115 | |||
116 | /** |
||
117 | * Allow enum instantiation by magic method |
||
118 | * |
||
119 | * @param string $name |
||
120 | * @param $arguments |
||
121 | * @return static |
||
122 | */ |
||
123 | public static function __callStatic($name, $arguments) |
||
133 | |||
134 | /** |
||
135 | * Return the values to be used in a loop |
||
136 | * |
||
137 | * @return ArrayIterator |
||
138 | */ |
||
139 | public function getIterator() |
||
143 | } |
||
144 |