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 | * Constructor method and sets default options, if any. |
||
59 | * |
||
60 | * @param array $input Input |
||
61 | */ |
||
62 | public function __construct($input) |
||
67 | |||
68 | /** |
||
69 | * Override this method in your own subclass to provide an array of default |
||
70 | * options and values. |
||
71 | 3 | * |
|
72 | * @return array |
||
73 | 3 | * |
|
74 | * @since 0.1.0 |
||
75 | 3 | */ |
|
76 | protected function getDefaults() |
||
80 | |||
81 | // KONFIGINTERFACE METHODS |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | * |
||
86 | * @return array Gets configuration items array |
||
87 | */ |
||
88 | public function all() |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | * |
||
96 | * @param string $key Configuration item key name item |
||
97 | * |
||
98 | 3 | * @return bool Returns true if the configuration item key exists |
|
99 | * |
||
100 | 3 | * @since 0.1.0 |
|
101 | * @codeCoverageIgnore |
||
102 | */ |
||
103 | public function has($key) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | * |
||
132 | * @param string $key Configuration item key name item |
||
133 | * @param string|array|null $default Default configuration |
||
134 | * |
||
135 | * @return string|array|null Default configuration |
||
136 | */ |
||
137 | public function get($key, $default = null) |
||
146 | |||
147 | 24 | /** |
|
148 | * {@inheritdoc} |
||
149 | 24 | * |
|
150 | * @param string $key Configuration item key name |
||
151 | 12 | * @param mixed $value Configuration item value |
|
152 | * |
||
153 | * @return void Void |
||
154 | 12 | */ |
|
155 | public function set($key, $value) |
||
193 | 6 | ||
194 | 5 | /** |
|
195 | 1 | * {@inheritdoc} |
|
196 | 6 | * |
|
197 | 6 | * @param string $key Configuration item key name |
|
198 | 6 | * |
|
199 | * @return bool |
||
200 | * @codeCoverageIgnore |
||
201 | 18 | */ |
|
202 | 18 | public function delete($key) |
|
211 | |||
212 | // ARRAYACCESS METHODS |
||
213 | |||
214 | /** |
||
215 | * Gets a value using the offset as a key. |
||
216 | * |
||
217 | * @param string $offset Configuration item key name |
||
218 | * |
||
219 | * @return mixed Configuration item |
||
220 | * |
||
221 | * @since 0.1.0 |
||
222 | */ |
||
223 | public function offsetGet($offset) |
||
227 | |||
228 | /** |
||
229 | * Checks if a key exists. |
||
230 | * |
||
231 | * @param string $offset Configuration item key name |
||
232 | * |
||
233 | 6 | * @return bool |
|
234 | * |
||
235 | 6 | * @since 0.1.0 |
|
236 | */ |
||
237 | public function offsetExists($offset) |
||
241 | |||
242 | /** |
||
243 | * Sets a value using the offset as a key. |
||
244 | * |
||
245 | * @param string $offset Configuration item key name |
||
246 | * @param mixed $value Configuration item value |
||
247 | 6 | * |
|
248 | * @return void Void |
||
249 | 6 | * @since 0.1.0 |
|
250 | */ |
||
251 | public function offsetSet($offset, $value) |
||
255 | |||
256 | /** |
||
257 | * Deletes a key and its value. |
||
258 | * |
||
259 | * @param string $offset Configuration item key name |
||
260 | * |
||
261 | 3 | * @return void Void |
|
262 | * @since 0.1.0 |
||
263 | 3 | */ |
|
264 | 3 | public function offsetUnset($offset) |
|
268 | |||
269 | // ITERATOR METHODS |
||
270 | |||
271 | /** |
||
272 | * Tests whether the iterator's current index is valid. |
||
273 | * |
||
274 | 3 | * @return bool True if the current index is valid; false otherwise |
|
275 | * |
||
276 | 3 | * @since 0.1.0 |
|
277 | 3 | */ |
|
278 | public function valid() |
||
282 | |||
283 | /** |
||
284 | * Returns the data array index referenced by its internal cursor. |
||
285 | * |
||
286 | * @return mixed The index referenced by the data array's internal cursor. |
||
287 | * If the array is empty or undefined or there is no element at the cursor, |
||
288 | 3 | * the function returns null. |
|
289 | * |
||
290 | 3 | * @since 0.1.0 |
|
291 | */ |
||
292 | public function key() |
||
296 | |||
297 | /** |
||
298 | * Returns the data array element referenced by its internal cursor. |
||
299 | * |
||
300 | * @return mixed The element referenced by the data array's internal cursor. |
||
301 | * If the array is empty or there is no element at the cursor, |
||
302 | 3 | * the function returns false. If the array is undefined, the function |
|
303 | * returns null |
||
304 | 3 | * |
|
305 | * @since 0.1.0 |
||
306 | */ |
||
307 | public function current() |
||
311 | |||
312 | /** |
||
313 | * Moves the data array's internal cursor forward one element. |
||
314 | * |
||
315 | * @return mixed The element referenced by the data array's internal cursor |
||
316 | * after the move is completed. If there are no more elements in the |
||
317 | 3 | * array after the move, the function returns false. If the data array |
|
318 | * is undefined, the function returns null. |
||
319 | 3 | * |
|
320 | * @since 0.1.0 |
||
321 | */ |
||
322 | public function next() |
||
326 | |||
327 | /** |
||
328 | * Moves the data array's internal cursor to the first element. |
||
329 | * |
||
330 | * @return mixed The element referenced by the data array's internal cursor |
||
331 | * after the move is completed. If the data array is empty, the function |
||
332 | 3 | * returns false. If the data array is undefined, the function returns null. |
|
333 | * |
||
334 | 3 | * @since 0.1.0 |
|
335 | */ |
||
336 | public function rewind() |
||
340 | } |
||
341 | |||
343 |