1 | <?php |
||
12 | class Configuration { |
||
13 | |||
14 | const KEYMARKER = '____'; |
||
15 | |||
16 | /** @var Setting[] metadata as array of Settings objects */ |
||
17 | protected $settings = array(); |
||
18 | /** @var array problematic keys */ |
||
19 | protected $errors; |
||
20 | /** @var Setting[] undefined settings */ |
||
21 | protected $undefined = array(); |
||
22 | |||
23 | /** @var array all metadata */ |
||
24 | protected $metadata; |
||
25 | /** @var array all default settings */ |
||
26 | protected $default; |
||
27 | /** @var array all local settings */ |
||
28 | protected $local; |
||
29 | /** @var array all protected settings */ |
||
30 | protected $protected; |
||
31 | |||
32 | /** @var bool have the settings been changed since loading from disk? */ |
||
33 | protected $changed = false; |
||
34 | |||
35 | /** @var Writer */ |
||
36 | protected $writer; |
||
37 | |||
38 | /** |
||
39 | * ConfigSettings constructor. |
||
40 | */ |
||
41 | public function __construct() { |
||
52 | |||
53 | /** |
||
54 | * Get all settings |
||
55 | * |
||
56 | * @return Setting[] |
||
57 | */ |
||
58 | public function getSettings() { |
||
61 | |||
62 | /** |
||
63 | * Get all unknown settings |
||
64 | * |
||
65 | * @return Setting[] |
||
66 | */ |
||
67 | public function getUndefined() { |
||
70 | |||
71 | /** |
||
72 | * Get the settings that had some kind of setup problem |
||
73 | * |
||
74 | * @return array associative error, key is the setting, value the error |
||
75 | */ |
||
76 | public function getErrors() { |
||
79 | |||
80 | /** |
||
81 | * Have the settings been changed since loading from disk? |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | public function hasChanged() { |
||
88 | |||
89 | /** |
||
90 | * Check if the config can be written |
||
91 | * |
||
92 | * @return bool |
||
93 | */ |
||
94 | public function isLocked() { |
||
97 | |||
98 | /** |
||
99 | * Update the settings using the data provided |
||
100 | * |
||
101 | * @param array $input as posted |
||
102 | * @return bool true if all updates went through, false on errors |
||
103 | */ |
||
104 | public function updateSettings($input) { |
||
117 | |||
118 | /** |
||
119 | * Save the settings |
||
120 | * |
||
121 | * @throws \Exception |
||
122 | */ |
||
123 | public function save() { |
||
126 | |||
127 | /** |
||
128 | * Touch the settings |
||
129 | * |
||
130 | * @throws \Exception |
||
131 | */ |
||
132 | public function touch() { |
||
135 | |||
136 | /** |
||
137 | * Initalizes the $settings and $undefined properties |
||
138 | */ |
||
139 | protected function initSettings() { |
||
162 | |||
163 | /** |
||
164 | * Instantiates the proper class for the given config key |
||
165 | * |
||
166 | * The class is added to the $settings or $undefined arrays and returned |
||
167 | * |
||
168 | * @param string $key |
||
169 | * @return Setting |
||
170 | */ |
||
171 | protected function instantiateClass($key) { |
||
183 | |||
184 | /** |
||
185 | * Return the class to load |
||
186 | * |
||
187 | * @param string $class the class name as given in the meta file |
||
188 | * @param string $key the settings key |
||
189 | * @return string |
||
190 | */ |
||
191 | protected function determineClassName($class, $key) { |
||
205 | |||
206 | } |
||
207 |