1 | <?php |
||
22 | class Config { |
||
23 | use |
||
24 | CRUD, |
||
25 | Singleton; |
||
26 | const INIT_STATE_METHOD = 'init'; |
||
27 | const SYSTEM_MODULE = 'System'; |
||
28 | const SYSTEM_THEME = 'CleverStyle'; |
||
29 | /** |
||
30 | * @var Cache\Prefix |
||
31 | */ |
||
32 | protected $cache; |
||
33 | /** |
||
34 | * Most of general configuration properties |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | public $core = []; |
||
39 | /** |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $core_internal = []; |
||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $last_language; |
||
47 | /** |
||
48 | * Configuration of databases, except the main database, parameters of which are stored in configuration file |
||
49 | * |
||
50 | * @var mixed[] |
||
51 | */ |
||
52 | public $db = []; |
||
53 | /** |
||
54 | * Configuration of storages, except the main storage, parameters of which are stored in configuration file |
||
55 | * |
||
56 | * @var mixed[] |
||
57 | */ |
||
58 | public $storage = []; |
||
59 | /** |
||
60 | * Internal structure of components parameters |
||
61 | * |
||
62 | * @var array[] |
||
63 | */ |
||
64 | public $components = []; |
||
65 | /** |
||
66 | * Array of all domains, which allowed to access the site |
||
67 | * |
||
68 | * Contains keys: |
||
69 | * * count - Total count |
||
70 | * * http - Insecure (http) domains |
||
71 | * * https - Secure (https) domains |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | public $mirrors; |
||
76 | protected $data_model = [ |
||
77 | 'domain' => 'text', |
||
78 | 'core' => 'json', |
||
79 | 'db' => 'json', |
||
80 | 'storage' => 'json', |
||
81 | 'components' => 'json' |
||
82 | ]; |
||
83 | protected $table = '[prefix]config'; |
||
84 | 4 | protected function cdb () { |
|
87 | /** |
||
88 | * Update multilingual options when language changes |
||
89 | */ |
||
90 | 54 | protected function init () { |
|
99 | /** |
||
100 | * Loading of configuration, initialization of $Config, $Cache, $L and Page objects, Routing processing |
||
101 | * |
||
102 | * @throws ExitException |
||
103 | */ |
||
104 | 54 | protected function construct () { |
|
105 | // TODO: Change `config2` to `config` in 6.x |
||
106 | 54 | $this->cache = Cache::prefix('config2'); |
|
107 | 54 | Event::instance()->fire('System/Config/init/before'); |
|
108 | 54 | $this->load_configuration(); |
|
109 | 54 | Event::instance()->fire('System/Config/init/after'); |
|
110 | 54 | if (!file_exists(MODULES.'/'.$this->core['default_module'])) { |
|
111 | 2 | $this->core['default_module'] = self::SYSTEM_MODULE; |
|
112 | 2 | $this->save(); |
|
113 | } |
||
114 | 54 | } |
|
115 | /** |
||
116 | * Reloading of settings cache |
||
117 | * |
||
118 | * @throws ExitException |
||
119 | */ |
||
120 | 54 | protected function load_configuration () { |
|
142 | /** |
||
143 | * Is used to fill `$this->mirrors` using current configuration |
||
144 | */ |
||
145 | 54 | protected function fill_mirrors () { |
|
158 | 54 | protected function read_core_update_multilingual () { |
|
159 | 54 | $language = Language::instance(true)->clanguage ?: @$this->core['language']; |
|
178 | /** |
||
179 | * Get core options item |
||
180 | * |
||
181 | * @param string[]|string[][] $item |
||
182 | * |
||
183 | * @return mixed|mixed[]|null Core options items (or associative array of items) if exists or `null` otherwise (in case if `$item` is an array even one |
||
184 | * missing key will cause the whole thing to fail) |
||
185 | */ |
||
186 | 2 | public function core (...$item) { |
|
187 | 2 | if (count($item) === 1) { |
|
188 | 2 | $item = $item[0]; |
|
189 | } |
||
190 | /** |
||
191 | * @var string|string[] $item |
||
192 | */ |
||
193 | 2 | if (is_array($item)) { |
|
194 | 2 | $result = []; |
|
195 | 2 | foreach ($item as &$i) { |
|
196 | 2 | if (!isset($this->core[$i])) { |
|
197 | 2 | return null; |
|
198 | } |
||
199 | 2 | $result[$i] = $this->core[$i]; |
|
200 | } |
||
201 | 2 | return $result; |
|
202 | } |
||
203 | /** @noinspection OffsetOperationsInspection */ |
||
204 | 2 | return @$this->core[$item]; |
|
205 | } |
||
206 | /** |
||
207 | * Applying settings without saving changes into db |
||
208 | * |
||
209 | * @return bool |
||
210 | * |
||
211 | * @throws ExitException |
||
212 | */ |
||
213 | 2 | public function apply () { |
|
230 | /** |
||
231 | * Applying settings without saving changes into db |
||
232 | * |
||
233 | * @param bool $cache_not_saved_mark |
||
234 | * |
||
235 | * @return bool |
||
236 | * |
||
237 | * @throws ExitException |
||
238 | */ |
||
239 | 2 | protected function apply_internal ($cache_not_saved_mark = true) { |
|
262 | /** |
||
263 | * Saving settings |
||
264 | * |
||
265 | * @return bool |
||
266 | * |
||
267 | * @throws ExitException |
||
268 | */ |
||
269 | 2 | public function save () { |
|
293 | /** |
||
294 | * Whether configuration was applied (not saved) and can be canceled |
||
295 | * |
||
296 | * @return bool |
||
297 | */ |
||
298 | 2 | public function cancel_available () { |
|
299 | 2 | return isset($this->core_internal['cache_not_saved']); |
|
300 | } |
||
301 | /** |
||
302 | * Canceling of applied settings |
||
303 | * |
||
304 | * @throws ExitException |
||
305 | */ |
||
306 | 2 | public function cancel () { |
|
310 | /** |
||
311 | * Get base url of current mirror including language suffix |
||
312 | * |
||
313 | * @return string |
||
314 | */ |
||
315 | 8 | public function base_url () { |
|
326 | /** |
||
327 | * Get base url of main domain |
||
328 | * |
||
329 | * @return string |
||
330 | */ |
||
331 | 14 | public function core_url () { |
|
335 | /** |
||
336 | * Get object for getting db and storage configuration of module |
||
337 | * |
||
338 | * @param string $module_name |
||
339 | * |
||
340 | * @return Config\Module_Properties |
||
341 | */ |
||
342 | 54 | public function module ($module_name) { |
|
349 | } |
||
350 |