1 | <?php |
||
17 | abstract class AbstractConfig implements ArrayAccess, ConfigInterface, Iterator |
||
18 | { |
||
19 | /** |
||
20 | * Stores the configuration data |
||
21 | * |
||
22 | * @var array|null |
||
23 | */ |
||
24 | protected $data = null; |
||
25 | |||
26 | /** |
||
27 | * Caches the configuration data |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $cache = array(); |
||
32 | |||
33 | /** |
||
34 | * Constructor method and sets default options, if any |
||
35 | * |
||
36 | * @param array $data |
||
37 | */ |
||
38 | 3 | public function __construct(Array $data) |
|
39 | { |
||
40 | 3 | $this->data = array_merge($this->getDefaults(), $data); |
|
41 | 3 | } |
|
42 | |||
43 | /** |
||
44 | * Override this method in your own subclass to provide an array of default |
||
45 | * options and values |
||
46 | * |
||
47 | * @return array |
||
48 | * |
||
49 | * @codeCoverageIgnore |
||
50 | */ |
||
51 | protected function getDefaults() |
||
55 | |||
56 | /** |
||
57 | * ConfigInterface Methods |
||
58 | */ |
||
59 | |||
60 | /** |
||
61 | * {@inheritDoc} |
||
62 | */ |
||
63 | 24 | public function get($key, $default = null) |
|
87 | |||
88 | /** |
||
89 | * {@inheritDoc} |
||
90 | */ |
||
91 | 18 | public function set($key, $value) |
|
126 | |||
127 | /** |
||
128 | * {@inheritDoc} |
||
129 | */ |
||
130 | 6 | public function has($key) |
|
134 | |||
135 | /** |
||
136 | * {@inheritDoc} |
||
137 | */ |
||
138 | 3 | public function all() |
|
142 | |||
143 | |||
144 | |||
145 | /** |
||
146 | * ArrayAccess Methods |
||
147 | */ |
||
148 | |||
149 | /** |
||
150 | * Gets a value using the offset as a key |
||
151 | * |
||
152 | * @param string $offset |
||
153 | * |
||
154 | * @return mixed |
||
155 | */ |
||
156 | 6 | public function offsetGet($offset) |
|
160 | |||
161 | /** |
||
162 | * Checks if a key exists |
||
163 | * |
||
164 | * @param string $offset |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | 6 | public function offsetExists($offset) |
|
172 | |||
173 | /** |
||
174 | * Sets a value using the offset as a key |
||
175 | * |
||
176 | * @param string $offset |
||
177 | * @param mixed $value |
||
178 | * |
||
179 | * @return void |
||
180 | */ |
||
181 | 3 | public function offsetSet($offset, $value) |
|
185 | |||
186 | /** |
||
187 | * Deletes a key and its value |
||
188 | * |
||
189 | * @param string $offset |
||
190 | * |
||
191 | * @return void |
||
192 | */ |
||
193 | 3 | public function offsetUnset($offset) |
|
197 | |||
198 | /** |
||
199 | * Iterator Methods |
||
200 | */ |
||
201 | |||
202 | /** |
||
203 | * Returns the data array element referenced by its internal cursor |
||
204 | * |
||
205 | * @return mixed The element referenced by the data array's internal cursor. |
||
206 | * If the array is empty or there is no element at the cursor, the |
||
207 | * function returns false. If the array is undefined, the function |
||
208 | * returns null |
||
209 | */ |
||
210 | 3 | public function current() |
|
214 | |||
215 | /** |
||
216 | * Returns the data array index referenced by its internal cursor |
||
217 | * |
||
218 | * @return mixed The index referenced by the data array's internal cursor. |
||
219 | * If the array is empty or undefined or there is no element at the |
||
220 | * cursor, the function returns null |
||
221 | */ |
||
222 | 3 | public function key() |
|
226 | |||
227 | /** |
||
228 | * Moves the data array's internal cursor forward one element |
||
229 | * |
||
230 | * @return mixed The element referenced by the data array's internal cursor |
||
231 | * after the move is completed. If there are no more elements in the |
||
232 | * array after the move, the function returns false. If the data array |
||
233 | * is undefined, the function returns null |
||
234 | */ |
||
235 | 3 | public function next() |
|
239 | |||
240 | /** |
||
241 | * Moves the data array's internal cursor to the first element |
||
242 | * |
||
243 | * @return mixed The element referenced by the data array's internal cursor |
||
244 | * after the move is completed. If the data array is empty, the function |
||
245 | * returns false. If the data array is undefined, the function returns |
||
246 | * null |
||
247 | */ |
||
248 | 3 | public function rewind() |
|
252 | |||
253 | /** |
||
254 | * Tests whether the iterator's current index is valid |
||
255 | * |
||
256 | * @return bool True if the current index is valid; false otherwise |
||
257 | */ |
||
258 | 3 | public function valid() |
|
262 | } |
||
263 |