1 | <?php namespace BuildR\Foundation\Enumeration; |
||
22 | abstract class AbstractEnumeration { |
||
23 | |||
24 | /** |
||
25 | * @type array |
||
26 | */ |
||
27 | private static $cache = []; |
||
28 | |||
29 | /** |
||
30 | * @type string |
||
31 | */ |
||
32 | protected $value; |
||
33 | |||
34 | /** |
||
35 | * AbstractEnumeration Constructor. Create a new instance from this enumeration. |
||
36 | * When the given value is not a valid element of the current enumeration a |
||
37 | * UnexpectedValueException will be thrown. |
||
38 | * |
||
39 | * @param string $value The |
||
40 | * |
||
41 | * @throws \BuildR\Foundation\Exception\UnexpectedValueException |
||
42 | */ |
||
43 | 20 | public function __construct($value) { |
|
50 | |||
51 | /** |
||
52 | * Returns the key of the current element |
||
53 | * |
||
54 | * @return NULL|string |
||
55 | */ |
||
56 | 1 | public function getKey() { |
|
62 | |||
63 | /** |
||
64 | * Returns the current element value |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | 1 | public function getValue() { |
|
71 | |||
72 | /** |
||
73 | * Validate the currently set value in the enumeration |
||
74 | * |
||
75 | * @param string $value |
||
76 | * |
||
77 | * @return bool |
||
78 | */ |
||
79 | 20 | public function isValid($value) { |
|
82 | |||
83 | /** |
||
84 | * Returns the current value as string representation |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | 1 | public function __toString() { |
|
91 | |||
92 | /** |
||
93 | * Translates the current enumeration class to an array. This function use |
||
94 | * runtime caching mechanism, all enumeration constants stored in a static |
||
95 | * value. |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | 20 | public static function toArray() { |
|
109 | |||
110 | /** |
||
111 | * Find a key in the enumeration by its value. If this value |
||
112 | * is exist in the current enumeration this function returns the |
||
113 | * corresponding key, NULL otherwise. |
||
114 | * |
||
115 | * @param string $value The value |
||
116 | * |
||
117 | * @return NULL|string |
||
118 | */ |
||
119 | 2 | public static function find($value) { |
|
124 | |||
125 | /** |
||
126 | * Returns the length of the current enumeration. |
||
127 | * |
||
128 | * @return ins |
||
129 | */ |
||
130 | 1 | public static function count() { |
|
133 | |||
134 | /** |
||
135 | * Returns all key from the current enumeration as array |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | 1 | public static function getKeys() { |
|
142 | |||
143 | /** |
||
144 | * Determines that the given key is exist in the current enumeration. |
||
145 | * If the key is not a string a BadMethodCallException will be thrown. |
||
146 | * |
||
147 | * @param string $key The desired key |
||
148 | * |
||
149 | * @return bool |
||
150 | * |
||
151 | * @throws \BuildR\Foundation\Exception\BadMethodCallException |
||
152 | */ |
||
153 | 7 | public static function isValidKey($key) { |
|
160 | |||
161 | /** |
||
162 | * This PHP magic method is a proxy for creating new instance from |
||
163 | * enumerations. The method name used as the class constructor parameter. |
||
164 | * The passed arguments ignored. Validation is not needed here because |
||
165 | * is handled by the constructor itself. |
||
166 | * |
||
167 | * @param string $name The method name |
||
168 | * @param array $arguments Passed arguments |
||
169 | * |
||
170 | * @return static |
||
171 | */ |
||
172 | 20 | public static function __callStatic($name, $arguments) { |
|
175 | } |
||
176 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.