1 | <?php |
||
37 | abstract class AbstractKonfig implements ArrayAccess, Iterator, KonfigInterface |
||
38 | { |
||
39 | /** |
||
40 | * Stores the configuration items. |
||
41 | * |
||
42 | * @var array Data |
||
43 | * |
||
44 | * @since 0.1.0 |
||
45 | */ |
||
46 | protected $data = []; |
||
47 | |||
48 | /** |
||
49 | * Caches the configuration data. |
||
50 | * |
||
51 | * @var array Cache |
||
52 | * |
||
53 | * @since 0.1.0 |
||
54 | */ |
||
55 | protected $cache = []; |
||
56 | |||
57 | /** |
||
58 | * Random value used as a not-found check in get(). |
||
59 | * |
||
60 | * @var string |
||
61 | * |
||
62 | * @since 0.1.0 |
||
63 | */ |
||
64 | protected static $defaultCheckValue; |
||
65 | |||
66 | /** |
||
67 | * Constructor method and sets default options, if any. |
||
68 | * |
||
69 | * @param array $input Input |
||
70 | */ |
||
71 | 3 | public function __construct($input) |
|
76 | |||
77 | /** |
||
78 | * Override this method in your own subclass to provide an array of default |
||
79 | * options and values. |
||
80 | * |
||
81 | * @return array |
||
82 | * |
||
83 | * @since 0.1.0 |
||
84 | * @codeCoverageIgnore |
||
85 | */ |
||
86 | protected function getDefaults() |
||
90 | |||
91 | // KONFIGINTERFACE METHODS |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | * |
||
96 | * @return array Gets configuration items array |
||
97 | */ |
||
98 | 3 | public function all() |
|
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | * |
||
106 | * @param string $key Configuration item key name item |
||
107 | * |
||
108 | * @return bool Returns true if the configuration item key exists |
||
109 | * |
||
110 | * @since 0.1.0 |
||
111 | */ |
||
112 | 6 | public function has($key) |
|
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | * |
||
141 | * @param string $key Configuration item key name item |
||
142 | * @param string|array|null $default Default configuration |
||
143 | * |
||
144 | * @return string|array|null Default configuration |
||
145 | */ |
||
146 | 24 | public function get($key, $default = null) |
|
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | * |
||
159 | * @param string $key Configuration item key name |
||
160 | * @param mixed $value Configuration item value |
||
161 | * |
||
162 | * @return void Void |
||
163 | */ |
||
164 | 18 | public function set($key, $value) |
|
202 | |||
203 | /** |
||
204 | * {@inheritdoc} |
||
205 | * |
||
206 | * @param string $key Configuration item key name |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | public function delete($key) |
||
219 | |||
220 | // ARRAYACCESS METHODS |
||
221 | |||
222 | /** |
||
223 | * Gets a value using the offset as a key. |
||
224 | * |
||
225 | * @param string $offset Configuration item key name |
||
226 | * |
||
227 | * @return mixed Configuration item |
||
228 | * |
||
229 | * @since 0.1.0 |
||
230 | */ |
||
231 | 6 | public function offsetGet($offset) |
|
235 | |||
236 | /** |
||
237 | * Checks if a key exists. |
||
238 | * |
||
239 | * @param string $offset Configuration item key name |
||
240 | * |
||
241 | * @return bool |
||
242 | * |
||
243 | * @since 0.1.0 |
||
244 | */ |
||
245 | 6 | public function offsetExists($offset) |
|
249 | |||
250 | /** |
||
251 | * Sets a value using the offset as a key. |
||
252 | * |
||
253 | * @param string $offset Configuration item key name |
||
254 | * @param mixed $value Configuration item value |
||
255 | * |
||
256 | * @return void Void |
||
257 | * @since 0.1.0 |
||
258 | */ |
||
259 | 3 | public function offsetSet($offset, $value) |
|
263 | |||
264 | /** |
||
265 | * Deletes a key and its value. |
||
266 | * |
||
267 | * @param string $offset Configuration item key name |
||
268 | * |
||
269 | * @return void Void |
||
270 | * @since 0.1.0 |
||
271 | */ |
||
272 | 3 | public function offsetUnset($offset) |
|
276 | |||
277 | // ITERATOR METHODS |
||
278 | |||
279 | /** |
||
280 | * Tests whether the iterator's current index is valid. |
||
281 | * |
||
282 | * @return bool True if the current index is valid; false otherwise |
||
283 | * |
||
284 | * @since 0.1.0 |
||
285 | */ |
||
286 | 3 | public function valid() |
|
290 | |||
291 | /** |
||
292 | * Returns the data array index referenced by its internal cursor. |
||
293 | * |
||
294 | * @return mixed The index referenced by the data array's internal cursor. |
||
295 | * If the array is empty or undefined or there is no element at the cursor, |
||
296 | * the function returns null. |
||
297 | * |
||
298 | * @since 0.1.0 |
||
299 | */ |
||
300 | 3 | public function key() |
|
304 | |||
305 | /** |
||
306 | * Returns the data array element referenced by its internal cursor. |
||
307 | * |
||
308 | * @return mixed The element referenced by the data array's internal cursor. |
||
309 | * If the array is empty or there is no element at the cursor, |
||
310 | * the function returns false. If the array is undefined, the function |
||
311 | * returns null |
||
312 | * |
||
313 | * @since 0.1.0 |
||
314 | */ |
||
315 | 3 | public function current() |
|
319 | |||
320 | /** |
||
321 | * Moves the data array's internal cursor forward one element. |
||
322 | * |
||
323 | * @return mixed The element referenced by the data array's internal cursor |
||
324 | * after the move is completed. If there are no more elements in the |
||
325 | * array after the move, the function returns false. If the data array |
||
326 | * is undefined, the function returns null. |
||
327 | * |
||
328 | * @since 0.1.0 |
||
329 | */ |
||
330 | 3 | public function next() |
|
334 | |||
335 | /** |
||
336 | * Moves the data array's internal cursor to the first element. |
||
337 | * |
||
338 | * @return mixed The element referenced by the data array's internal cursor |
||
339 | * after the move is completed. If the data array is empty, the function |
||
340 | * returns false. If the data array is undefined, the function returns null. |
||
341 | * |
||
342 | * @since 0.1.0 |
||
343 | */ |
||
344 | 3 | public function rewind() |
|
348 | |||
349 | /** |
||
350 | * __toString. |
||
351 | * |
||
352 | * @return string |
||
353 | * |
||
354 | * @since 0.1.2 |
||
355 | * @codeCoverageIgnore |
||
356 | */ |
||
357 | public function __toString() |
||
361 | } |
||
362 | |||
364 |