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) |
|
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) |
|
71 | |||
72 | /** |
||
73 | * {@inheritDoc} |
||
74 | */ |
||
75 | 18 | public function set($key, $value) |
|
110 | |||
111 | /** |
||
112 | * {@inheritDoc} |
||
113 | */ |
||
114 | 6 | public function has($key) |
|
139 | |||
140 | /** |
||
141 | * Merge config from another instance |
||
142 | * |
||
143 | 3 | * @param ConfigInterface $config |
|
144 | * @return ConfigInterface |
||
145 | 3 | */ |
|
146 | public function merge(ConfigInterface $config) |
||
151 | |||
152 | /** |
||
153 | * {@inheritDoc} |
||
154 | */ |
||
155 | public function all() |
||
159 | 6 | ||
160 | /** |
||
161 | 6 | * ArrayAccess Methods |
|
162 | */ |
||
163 | |||
164 | /** |
||
165 | * Gets a value using the offset as a key |
||
166 | * |
||
167 | * @param string $offset |
||
168 | * |
||
169 | * @return mixed |
||
170 | */ |
||
171 | 6 | public function offsetGet($offset) |
|
175 | |||
176 | /** |
||
177 | * Checks if a key exists |
||
178 | * |
||
179 | * @param string $offset |
||
180 | * |
||
181 | * @return bool |
||
182 | */ |
||
183 | public function offsetExists($offset) |
||
187 | 3 | ||
188 | /** |
||
189 | * Sets a value using the offset as a key |
||
190 | * |
||
191 | * @param string $offset |
||
192 | * @param mixed $value |
||
193 | * |
||
194 | * @return void |
||
195 | */ |
||
196 | 3 | public function offsetSet($offset, $value) |
|
200 | |||
201 | /** |
||
202 | * Deletes a key and its value |
||
203 | * |
||
204 | * @param string $offset |
||
205 | * |
||
206 | * @return void |
||
207 | */ |
||
208 | public function offsetUnset($offset) |
||
212 | |||
213 | 3 | /** |
|
214 | * Iterator Methods |
||
215 | 3 | */ |
|
216 | |||
217 | /** |
||
218 | * Returns the data array element referenced by its internal cursor |
||
219 | * |
||
220 | * @return mixed The element referenced by the data array's internal cursor. |
||
221 | * If the array is empty or there is no element at the cursor, the |
||
222 | * function returns false. If the array is undefined, the function |
||
223 | * returns null |
||
224 | */ |
||
225 | 3 | public function current() |
|
229 | |||
230 | /** |
||
231 | * Returns the data array index referenced by its internal cursor |
||
232 | * |
||
233 | * @return mixed The index referenced by the data array's internal cursor. |
||
234 | * If the array is empty or undefined or there is no element at the |
||
235 | * cursor, the function returns null |
||
236 | */ |
||
237 | public function key() |
||
241 | |||
242 | /** |
||
243 | * Moves the data array's internal cursor forward one element |
||
244 | * |
||
245 | * @return mixed The element referenced by the data array's internal cursor |
||
246 | * after the move is completed. If there are no more elements in the |
||
247 | * array after the move, the function returns false. If the data array |
||
248 | * is undefined, the function returns null |
||
249 | */ |
||
250 | public function next() |
||
254 | |||
255 | /** |
||
256 | * Moves the data array's internal cursor to the first element |
||
257 | * |
||
258 | * @return mixed The element referenced by the data array's internal cursor |
||
259 | * after the move is completed. If the data array is empty, the function |
||
260 | * returns false. If the data array is undefined, the function returns |
||
261 | 3 | * null |
|
262 | */ |
||
263 | 3 | public function rewind() |
|
267 | |||
268 | /** |
||
269 | * Tests whether the iterator's current index is valid |
||
270 | * |
||
271 | * @return bool True if the current index is valid; false otherwise |
||
272 | */ |
||
273 | 3 | public function valid() |
|
277 | |||
278 | /** |
||
279 | * Remove a value using the offset as a key |
||
280 | * |
||
281 | * @param string $key |
||
282 | * |
||
283 | * @return void |
||
284 | */ |
||
285 | public function remove($key) |
||
289 | } |
||
290 |