1 | <?php |
||
5 | class Config |
||
6 | { |
||
7 | /** |
||
8 | * Current configuration settings |
||
9 | * @var array |
||
10 | */ |
||
11 | private $config = array(); |
||
12 | |||
13 | /** |
||
14 | * Init the object and set the path |
||
15 | * Loading happens by default unless second param is false |
||
16 | * |
||
17 | * @param string $path Path to configuration file |
||
18 | * @param boolean $load Turn autoloading on/off [optional] |
||
19 | */ |
||
20 | public function __construct($path, $load = true) |
||
27 | |||
28 | /** |
||
29 | * Set the path to the configuration file |
||
30 | * |
||
31 | * @param string $path Configuration file path |
||
32 | */ |
||
33 | public function setPath($path) |
||
40 | |||
41 | /** |
||
42 | * Get the current path setting |
||
43 | * |
||
44 | * @return string Path to current configuration file |
||
45 | */ |
||
46 | public function getPath() |
||
50 | |||
51 | /** |
||
52 | * Load the configuration data into the object |
||
53 | * from the defined YAML file |
||
54 | * |
||
55 | * @return array Set of configuration data |
||
56 | */ |
||
57 | public function load() |
||
67 | |||
68 | /** |
||
69 | * Get the current configuration data |
||
70 | * Optionally, if a key is provided and set, onyl that value is returned |
||
71 | * |
||
72 | * @param string $key Configuration key to locate [optional] |
||
73 | * @return array|string All config data or just key if found |
||
74 | */ |
||
75 | public function getConfig($key = null) |
||
80 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: