1 | <?php |
||
21 | abstract class AbstractKonfig implements ArrayAccess, Iterator, KonfigInterface |
||
22 | { |
||
23 | /** |
||
24 | * Stores the configuration items |
||
25 | * |
||
26 | * @var array |
||
27 | * @since 0.1.0 |
||
28 | */ |
||
29 | protected $data = []; |
||
30 | |||
31 | /** |
||
32 | * Caches the configuration data |
||
33 | * |
||
34 | * @var array |
||
35 | * @since 0.1.0 |
||
36 | */ |
||
37 | protected $cache = []; |
||
38 | |||
39 | /** |
||
40 | * @var string $defaultCheckValue Random value used as a not-found check in get() |
||
41 | * @since 0.1.0 |
||
42 | */ |
||
43 | static protected $defaultCheckValue; |
||
44 | |||
45 | /** |
||
46 | * Constructor method and sets default options, if any |
||
47 | * |
||
48 | * @param array $input |
||
49 | 3 | * @since 0.1.0 |
|
50 | */ |
||
51 | 3 | public function __construct($input) |
|
56 | |||
57 | /** |
||
58 | * Override this method in your own subclass to provide an array of default |
||
59 | * options and values |
||
60 | * |
||
61 | * @codeCoverageIgnore |
||
62 | * @return array |
||
63 | * @since 0.1.0 |
||
64 | */ |
||
65 | protected function getDefaults() |
||
69 | |||
70 | 3 | #: KonfigInterface Methods |
|
71 | |||
72 | 3 | public function all() |
|
76 | |||
77 | /** |
||
78 | 6 | * {@inheritDoc} |
|
79 | */ |
||
80 | public function has($key) |
||
105 | |||
106 | /** |
||
107 | 24 | * {@inheritDoc} |
|
108 | */ |
||
109 | 24 | public function get($key, $default = null) |
|
117 | |||
118 | /** |
||
119 | 18 | * {@inheritDoc} |
|
120 | */ |
||
121 | 18 | public function set($key, $value) |
|
159 | |||
160 | /** |
||
161 | * {@inheritDoc} |
||
162 | */ |
||
163 | public function delete($key) |
||
172 | |||
173 | #: ArrayAccess Methods |
||
174 | |||
175 | /** |
||
176 | * Gets a value using the offset as a key |
||
177 | * |
||
178 | * @param string $offset |
||
179 | 6 | * @return mixed |
|
180 | * @since 0.1.0 |
||
181 | 6 | */ |
|
182 | public function offsetGet($offset) |
||
186 | |||
187 | /** |
||
188 | * Checks if a key exists |
||
189 | * |
||
190 | * @param string $offset |
||
191 | 6 | * @return bool |
|
192 | * @since 0.1.0 |
||
193 | 6 | */ |
|
194 | public function offsetExists($offset) |
||
198 | |||
199 | /** |
||
200 | * Sets a value using the offset as a key |
||
201 | * |
||
202 | * @param string $offset |
||
203 | * @param mixed $value |
||
204 | 3 | * @return void |
|
205 | * @since 0.1.0 |
||
206 | 3 | */ |
|
207 | 3 | public function offsetSet($offset, $value) |
|
211 | |||
212 | /** |
||
213 | * Deletes a key and its value |
||
214 | * |
||
215 | * @param string $offset |
||
216 | 3 | * @return void |
|
217 | * @since 0.1.0 |
||
218 | 3 | */ |
|
219 | 3 | public function offsetUnset($offset) |
|
223 | |||
224 | #: Iterator Methods |
||
225 | |||
226 | /** |
||
227 | * Tests whether the iterator's current index is valid |
||
228 | * |
||
229 | 3 | * @return bool True if the current index is valid; false otherwise |
|
230 | * @since 0.1.0 |
||
231 | 3 | */ |
|
232 | public function valid() |
||
236 | |||
237 | /** |
||
238 | * Returns the data array index referenced by its internal cursor |
||
239 | * |
||
240 | * @return mixed The index referenced by the data array's internal cursor. |
||
241 | * If the array is empty or undefined or there is no element at the cursor, |
||
242 | 3 | * the function returns null |
|
243 | * @since 0.1.0 |
||
244 | 3 | */ |
|
245 | public function key() |
||
249 | |||
250 | /** |
||
251 | * Returns the data array element referenced by its internal cursor |
||
252 | * |
||
253 | * @return mixed The element referenced by the data array's internal cursor. |
||
254 | * If the array is empty or there is no element at the cursor, |
||
255 | * the function returns false. If the array is undefined, the function |
||
256 | 3 | * returns null |
|
257 | * @since 0.1.0 |
||
258 | 3 | */ |
|
259 | public function current() |
||
263 | |||
264 | /** |
||
265 | * Moves the data array's internal cursor forward one element |
||
266 | * |
||
267 | * @return mixed The element referenced by the data array's internal cursor |
||
268 | * after the move is completed. If there are no more elements in the |
||
269 | * array after the move, the function returns false. If the data array |
||
270 | 3 | * is undefined, the function returns null |
|
271 | * @since 0.1.0 |
||
272 | 3 | */ |
|
273 | public function next() |
||
277 | |||
278 | /** |
||
279 | * Moves the data array's internal cursor to the first element |
||
280 | * |
||
281 | * @return mixed The element referenced by the data array's internal cursor |
||
282 | * after the move is completed. If the data array is empty, the function |
||
283 | 3 | * returns false. If the data array is undefined, the function returns null |
|
284 | * @since 0.1.0 |
||
285 | 3 | */ |
|
286 | public function rewind() |
||
290 | |||
291 | /** |
||
292 | * @return string |
||
293 | * @since 0.1.2 |
||
294 | */ |
||
295 | public function __toString() |
||
299 | } |
||
300 | |||
302 |