1 | <?php |
||
40 | class Config |
||
41 | { |
||
42 | /** |
||
43 | * The currently set default values in a multi-dimensional array. |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $defaultValues = []; |
||
47 | |||
48 | /** |
||
49 | * The currently set values in a multi-dimensional array. |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $values = []; |
||
53 | |||
54 | /** |
||
55 | * Add a new array element to the specified configuration path. |
||
56 | * Warning: If the current value is not an array, it is overwritten. |
||
57 | * |
||
58 | * @param string|array $name The configuration path |
||
59 | * @param mixed $value |
||
60 | * |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function add($name, $value) |
||
83 | |||
84 | /** |
||
85 | * Set the value at the specified configuration path. |
||
86 | * |
||
87 | * @param string|array $name The configuration path |
||
88 | * @param mixed $value |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function set($name, $value) |
||
97 | |||
98 | /** |
||
99 | * Set the default fallback value for the specified configuration path. |
||
100 | * |
||
101 | * @param string|array $name The configuration path |
||
102 | * @param mixed $value |
||
103 | * |
||
104 | * @return $this |
||
105 | */ |
||
106 | public function setDefault($name, $value) |
||
111 | |||
112 | /** |
||
113 | * Return the value for the specified configuration path. |
||
114 | * If this value is not set, return the default value. |
||
115 | * Return null if not set. |
||
116 | * |
||
117 | * @param string $name The configuration path |
||
118 | * |
||
119 | * @return mixed |
||
120 | */ |
||
121 | public function get($name) |
||
137 | |||
138 | /** |
||
139 | * Return the default value for the specified configuration path. |
||
140 | * Return null if not set. |
||
141 | * |
||
142 | * @param string $name The configuration path |
||
143 | * |
||
144 | * @return mixed |
||
145 | */ |
||
146 | public function getDefault($name) |
||
164 | |||
165 | /** |
||
166 | * Import a JSON file and parse it. |
||
167 | * Return true on success, false if the file does not exists. |
||
168 | * |
||
169 | * @param string $file The path to the file. |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | public function importJSON($file) |
||
183 | |||
184 | /** |
||
185 | * Recursively set all the values from an array. |
||
186 | * Usually used when importing. |
||
187 | * |
||
188 | * @param array $array |
||
189 | * @param array $current_path |
||
190 | */ |
||
191 | protected function setFromArrayRecursive($array, $current_path = []) |
||
201 | |||
202 | protected function _set($name, $value, $is_default = false) |
||
220 | } |
||
221 |