2018-10-04 21:01:17 +02:00
|
|
|
<?php
|
|
|
|
define('MSZ_CONFIG_STORE', '_msz_configuration_store');
|
|
|
|
|
|
|
|
function config_load(string $path, bool $isText = false): void
|
|
|
|
{
|
|
|
|
$config = $isText
|
|
|
|
? parse_ini_string($path, true, INI_SCANNER_TYPED)
|
|
|
|
: parse_ini_file($path, true, INI_SCANNER_TYPED);
|
|
|
|
|
2018-10-04 22:30:55 +02:00
|
|
|
if (!is_array($GLOBALS[MSZ_CONFIG_STORE] ?? null)) {
|
2018-10-04 21:01:17 +02:00
|
|
|
$GLOBALS[MSZ_CONFIG_STORE] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$GLOBALS[MSZ_CONFIG_STORE] = array_merge_recursive($GLOBALS[MSZ_CONFIG_STORE], $config);
|
|
|
|
}
|
|
|
|
|
2018-10-04 22:30:55 +02:00
|
|
|
function config_get(string ...$key)
|
2018-10-04 21:01:17 +02:00
|
|
|
{
|
2018-10-04 22:30:55 +02:00
|
|
|
$value = $GLOBALS[MSZ_CONFIG_STORE];
|
2018-10-04 21:01:17 +02:00
|
|
|
|
2018-10-04 22:30:55 +02:00
|
|
|
for ($i = 0; $i < count($key); $i++) {
|
|
|
|
if (empty($value[$key[$i]])) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = $value[$key[$i]];
|
2018-10-04 21:01:17 +02:00
|
|
|
}
|
|
|
|
|
2018-10-04 22:30:55 +02:00
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function config_get_default($default, string ...$key)
|
|
|
|
{
|
|
|
|
return config_get(...$key) ?? $default;
|
2018-10-04 21:01:17 +02:00
|
|
|
}
|