1 | <?php |
||
15 | class Config implements \ArrayAccess |
||
16 | { |
||
17 | /** |
||
18 | * Holds the config array. |
||
19 | * @var array |
||
20 | */ |
||
21 | public $config = array(); |
||
22 | |||
23 | /** |
||
24 | * TEMP: Holds the singleton instance. |
||
25 | * @var Config |
||
26 | */ |
||
27 | private static $instance = null; |
||
28 | |||
29 | /** |
||
30 | * TEMP: Returns as a singleton instance. |
||
31 | * |
||
32 | * @return Config |
||
33 | */ |
||
34 | public static function getInstance($config=null) |
||
35 | { |
||
36 | if (null === self::$instance) { |
||
37 | self::$instance = new self($config); |
||
38 | } |
||
39 | |||
40 | return self::$instance; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * TEMP: disalow cloning. |
||
45 | * |
||
46 | * @codeCoverageIgnore |
||
47 | */ |
||
48 | final private function __clone() {} |
||
49 | |||
50 | /** |
||
51 | * Initialises and sets the config property. |
||
52 | * |
||
53 | * @return Config |
||
|
|||
54 | */ |
||
55 | public function __construct($config=null) |
||
82 | |||
83 | /** |
||
84 | * Sets the config array from a file. |
||
85 | * |
||
86 | * @param string $file The full path to a configuration file. |
||
87 | * @throws \RuntimeException |
||
88 | * @return void; |
||
89 | */ |
||
90 | public function getConfigFromFile($file) |
||
109 | |||
110 | /** |
||
111 | * Sets the config property and merge the defaults. |
||
112 | * |
||
113 | * @param array $config=null |
||
114 | */ |
||
115 | public function setConfig(array $config=null) |
||
120 | |||
121 | /** |
||
122 | * Returns the config array. |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | public function getConfig() |
||
130 | |||
131 | /** |
||
132 | * Returns the specified config value using its index key. If the index key |
||
133 | * is not set then it will return the whole config property. |
||
134 | * |
||
135 | * @param string $key=null The key to retrieve. |
||
136 | * @return mixed |
||
137 | * @throws \InvalidArgumentException |
||
138 | */ |
||
139 | public function get($key=null) |
||
151 | |||
152 | /** |
||
153 | * Sets as new a mixed value to a specified key. |
||
154 | * |
||
155 | * @param string $key The key to set. |
||
156 | * @param mixed $mix The mixed value to set. |
||
157 | */ |
||
158 | public function set($key, $mix) |
||
162 | |||
163 | /** |
||
164 | * Adds the mixed value to a specified key. |
||
165 | * |
||
166 | * @param string $key The key to add to. |
||
167 | * @param mixed $mix The mixed value to add. |
||
168 | */ |
||
169 | public function add($key, $mix) |
||
173 | |||
174 | /** |
||
175 | * Returns the specified default config value using its index key. |
||
176 | * If the index key is not set then it will return the whole default config property. |
||
177 | * |
||
178 | * @param string $key=null The key to retrieve. |
||
179 | * @return mixed |
||
180 | * @throws \InvalidArgumentException |
||
181 | */ |
||
182 | public function getDefault($key=null) |
||
194 | |||
195 | /** |
||
196 | * Returns a specified sub-array type from config. |
||
197 | * If an index key is specified return the corresponding (mixed) value. |
||
198 | * |
||
199 | * @param string $type The sub-array type to retrieve. |
||
200 | * @param string $key=null A key to narrow the retrieval. |
||
201 | * @return mixed |
||
202 | * @throws \InvalidArgumentException |
||
203 | */ |
||
204 | public function retrieve($type, $key=null) |
||
221 | |||
222 | /** |
||
223 | * Returns all the resources or as the specified. |
||
224 | * |
||
225 | * @param string $key=null The resource key to retrieve. |
||
226 | * @see self::retrieve |
||
227 | */ |
||
228 | public function getResources($key=null) |
||
232 | |||
233 | /** |
||
234 | * TEMP: Returns the default configuration. |
||
235 | * TODO: should use 'config.dist.php' |
||
236 | * |
||
237 | * @return array |
||
238 | */ |
||
239 | public function getConfigDefaults() |
||
246 | |||
247 | /** |
||
248 | * Returns the specified service -- or all if unspecified. |
||
249 | * |
||
250 | * @param string $key=null The service key to retrieve. |
||
251 | * @see self::retrieve |
||
252 | * @return mixed Generally should return a callback |
||
253 | */ |
||
254 | public function getServices($key=null, $args=null) |
||
260 | |||
261 | /** |
||
262 | * Sets the specified name, value as a service. |
||
263 | * |
||
264 | * @param string $name The service name to set. |
||
265 | * @param mixed $mix The corresponding value to set. |
||
266 | * @return void |
||
267 | */ |
||
268 | public function setService($name, $mix) |
||
272 | |||
273 | /** |
||
274 | * {@inheritdoc} |
||
275 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
276 | * @param mixed $offset - An offset to check for. |
||
277 | * @return boolean true on success or false on failure. |
||
278 | */ |
||
279 | public function offsetExists($offset) |
||
283 | |||
284 | /** |
||
285 | * {@inheritdoc} |
||
286 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
287 | * @param mixed $offset The offset to retrieve. |
||
288 | * @return mixed Can return all value types. |
||
289 | */ |
||
290 | public function offsetGet($offset) |
||
294 | |||
295 | /** |
||
296 | * {@inheritdoc} |
||
297 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
298 | * @param mixed $offset The offset to assign the value to. |
||
299 | * @param mixed $value The value to set. |
||
300 | * @return void |
||
301 | */ |
||
302 | public function offsetSet($offset, $value) |
||
306 | |||
307 | /** |
||
308 | * {@inheritdoc} |
||
309 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
310 | * @param mixed $offset The offset to unset. |
||
311 | * @return void |
||
312 | */ |
||
313 | public function offsetUnset($offset) |
||
317 | |||
318 | /* --- below obsolete --- */ |
||
319 | |||
320 | /** |
||
321 | * TEMP: Holds the injected array. |
||
322 | * @var array |
||
323 | */ |
||
324 | private $injected; |
||
325 | |||
326 | /** |
||
327 | * TEMP: Sets/injects a key/value pair in the injected array. |
||
328 | * |
||
329 | * @param string $key An index key to set. |
||
330 | * @param mixed $value The value to inject. |
||
331 | * @return void |
||
332 | */ |
||
333 | public function inject($key, $value) |
||
337 | |||
338 | /** |
||
339 | * TEMP: Returns the specified injected key. |
||
340 | * |
||
341 | * @param string $key The index key to retrieve. |
||
342 | * @return mixed |
||
343 | */ |
||
344 | public function getInjected($key) |
||
348 | |||
349 | } |
||
350 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.