new config system but not finished
This commit is contained in:
parent
0f79e2015c
commit
d0ddd07079
1 changed files with 28 additions and 0 deletions
28
src/config.php
Normal file
28
src/config.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?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);
|
||||||
|
|
||||||
|
if (!is_array($GLOBALS[MSZ_CONFIG_STORE])) {
|
||||||
|
$GLOBALS[MSZ_CONFIG_STORE] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$GLOBALS[MSZ_CONFIG_STORE] = array_merge_recursive($GLOBALS[MSZ_CONFIG_STORE], $config);
|
||||||
|
}
|
||||||
|
|
||||||
|
function config_get(string $key, $default = null)
|
||||||
|
{
|
||||||
|
$lastDot = strrpos($key, '.');
|
||||||
|
|
||||||
|
if ($lastDot !== false) {
|
||||||
|
$section = substr($key, 0, $lastDot);
|
||||||
|
$key = substr($key, $lastDot + 1);
|
||||||
|
return $GLOBALS[MSZ_CONFIG_STORE][$section][$key] ?? $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $GLOBALS[MSZ_CONFIG_STORE][$key] ?? $default;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue