1 | <?php |
||
9 | class Config |
||
10 | { |
||
11 | use PathHelpers; |
||
12 | |||
13 | /** |
||
14 | * Instance of self. |
||
15 | * |
||
16 | * @var Config |
||
17 | */ |
||
18 | private static $instance; |
||
19 | |||
20 | /** |
||
21 | * Phalcon config instance. |
||
22 | * |
||
23 | * @var PhalconConfig |
||
24 | */ |
||
25 | protected $config; |
||
26 | |||
27 | /** |
||
28 | * The original config array. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $original; |
||
33 | |||
34 | /** |
||
35 | * Default setting values. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | const DEFAULTS = [ |
||
40 | 'migratorType' => 'fileDate', |
||
41 | 'migrationRepository' => 'database', |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * Private constructor. |
||
46 | * |
||
47 | * @param array $configArray |
||
48 | */ |
||
49 | private function __construct() |
||
52 | |||
53 | /** |
||
54 | * Get config values by key from PhalconConfig. |
||
55 | * |
||
56 | * @param string $key |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | public function __get($key) |
||
68 | |||
69 | /** |
||
70 | * Get instance of self with config array set. |
||
71 | * |
||
72 | * @param array $configArray |
||
73 | * |
||
74 | * @return Config |
||
75 | */ |
||
76 | public static function getInstance() |
||
84 | |||
85 | /** |
||
86 | * Set config using config data in di or passed data. |
||
87 | * |
||
88 | * @param array|string $userConfig If string, config path. If array, data. |
||
89 | * @param bool $merge If true, merge given config array into current. |
||
90 | */ |
||
91 | public function setConfig($userConfig = null, $merge = true) |
||
111 | |||
112 | /** |
||
113 | * Get a value by key from config. |
||
114 | * |
||
115 | * @param string|array $key |
||
116 | * |
||
117 | * @return mixed |
||
118 | */ |
||
119 | public function get($key) |
||
123 | |||
124 | /** |
||
125 | * Get nested values. |
||
126 | * |
||
127 | * @param array $keyArray |
||
128 | * |
||
129 | * @return mixed |
||
130 | */ |
||
131 | public function getNested(array $keyArray) |
||
145 | |||
146 | /** |
||
147 | * Return true if config array has given value. |
||
148 | * |
||
149 | * @param mixed $value |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function has($value) |
||
169 | |||
170 | /** |
||
171 | * Get a setting's default value. |
||
172 | * |
||
173 | * @param string $key |
||
174 | * |
||
175 | * @return mixed|null |
||
176 | */ |
||
177 | public function getDefault($key) |
||
185 | |||
186 | /** |
||
187 | * Set an item in the config. |
||
188 | * |
||
189 | * @param mixed $keys |
||
190 | * @param mixed $value |
||
191 | */ |
||
192 | public function set($keys, $value) |
||
210 | |||
211 | /** |
||
212 | * Remove an item from the config. |
||
213 | * |
||
214 | * @param mixed $keys |
||
215 | */ |
||
216 | public function remove($keys) |
||
232 | |||
233 | /** |
||
234 | * Set the config array to its original values. |
||
235 | */ |
||
236 | public function refresh() |
||
240 | |||
241 | /** |
||
242 | * Return the config array. |
||
243 | * |
||
244 | * @return array |
||
245 | */ |
||
246 | public function toArray() |
||
254 | |||
255 | /** |
||
256 | * Make a variable an array if not one already. |
||
257 | * |
||
258 | * @param mixed $value |
||
259 | * |
||
260 | * @return array |
||
261 | */ |
||
262 | protected function makeArray($value) |
||
270 | |||
271 | /** |
||
272 | * Validate that a setting exists. |
||
273 | * |
||
274 | * @param array $settings |
||
275 | * |
||
276 | * @throws InvalidConfig |
||
277 | */ |
||
278 | public function validate(array $settings) |
||
284 | |||
285 | /** |
||
286 | * Merge the given config with the current one. |
||
287 | * |
||
288 | * @param PhalconConfig $config |
||
289 | */ |
||
290 | public function merge(PhalconConfig $config) |
||
294 | |||
295 | /** |
||
296 | * Return the config key count. |
||
297 | * |
||
298 | * @return int |
||
299 | */ |
||
300 | public function count() |
||
304 | } |
||
305 |