1 | <?php |
||
8 | class Config |
||
9 | { |
||
10 | use PathHelpers; |
||
11 | |||
12 | /** |
||
13 | * Instance of self. |
||
14 | * |
||
15 | * @var Config |
||
16 | */ |
||
17 | private static $instance; |
||
18 | |||
19 | /** |
||
20 | * Yarak config array. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $configArray; |
||
25 | |||
26 | /** |
||
27 | * Default setting values. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | const DEFAULTS = [ |
||
32 | 'migratorType' => 'fileDate', |
||
33 | 'migrationRepository' => 'database', |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * Private constructor. |
||
38 | * |
||
39 | * @param array $configArray |
||
40 | */ |
||
41 | private function __construct(array $configArray) |
||
45 | |||
46 | /** |
||
47 | * Get instance of self with config array set. |
||
48 | * |
||
49 | * @param array $configArray |
||
50 | * |
||
51 | * @return Config |
||
52 | */ |
||
53 | public static function getInstance(array $configArray = []) |
||
65 | |||
66 | /** |
||
67 | * Get the set config array. |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | public static function getSetConfigArray() |
||
77 | |||
78 | /** |
||
79 | * Get a value from the config array. |
||
80 | * |
||
81 | * @param string|array $value |
||
82 | * |
||
83 | * @return mixed |
||
84 | */ |
||
85 | public function get($value) |
||
99 | |||
100 | /** |
||
101 | * Return true if config array has given value. |
||
102 | * |
||
103 | * @param mixed $value |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function has($value) |
||
111 | |||
112 | /** |
||
113 | * Get a setting's default value. |
||
114 | * |
||
115 | * @param string $value |
||
116 | * |
||
117 | * @return mixed|null |
||
118 | */ |
||
119 | public function getDefault($value) |
||
125 | |||
126 | /** |
||
127 | * Set an item in the config. |
||
128 | * |
||
129 | * @param mixed $keys |
||
130 | * @param mixed $value |
||
131 | */ |
||
132 | public function set($keys, $value) |
||
142 | |||
143 | /** |
||
144 | * Remove an item from the config. |
||
145 | * |
||
146 | * @param mixed $keys |
||
147 | */ |
||
148 | public function remove($keys) |
||
162 | |||
163 | /** |
||
164 | * Set the config array to its original values. |
||
165 | */ |
||
166 | public function refresh() |
||
170 | |||
171 | /** |
||
172 | * Return the config array. |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | public function toArray() |
||
180 | |||
181 | /** |
||
182 | * Make a variable an array if not one already. |
||
183 | * |
||
184 | * @param mixed $value |
||
185 | * |
||
186 | * @return array |
||
187 | */ |
||
188 | protected function makeArray($value) |
||
196 | |||
197 | /** |
||
198 | * Validate that a setting exists. |
||
199 | * |
||
200 | * @param array $settings |
||
201 | * |
||
202 | * @throws InvalidConfig |
||
203 | */ |
||
204 | public function validate(array $settings) |
||
210 | } |
||
211 |