Refactor ConfigFileManager

This commit is contained in:
Art4 2024-11-19 07:48:43 +00:00
parent cde93c68dc
commit 58e447f7bb

View file

@ -245,59 +245,61 @@ class ConfigFileManager
$fullName = $this->baseDir . DIRECTORY_SEPARATOR . '.' . $name . '.php'; $fullName = $this->baseDir . DIRECTORY_SEPARATOR . '.' . $name . '.php';
$config = []; $config = [];
if (file_exists($fullName)) { if (!file_exists($fullName)) {
$a = new \stdClass(); return $config;
$a->config = []; }
include $fullName;
$htConfigCategories = array_keys($a->config); $a = new \stdClass();
$a->config = [];
include $fullName;
// map the legacy configuration structure to the current structure $htConfigCategories = array_keys($a->config);
foreach ($htConfigCategories as $htConfigCategory) {
if (is_array($a->config[$htConfigCategory])) {
$keys = array_keys($a->config[$htConfigCategory]);
foreach ($keys as $key) { // map the legacy configuration structure to the current structure
$config[$htConfigCategory][$key] = $a->config[$htConfigCategory][$key]; foreach ($htConfigCategories as $htConfigCategory) {
} if (is_array($a->config[$htConfigCategory])) {
} else { $keys = array_keys($a->config[$htConfigCategory]);
$config['config'][$htConfigCategory] = $a->config[$htConfigCategory];
foreach ($keys as $key) {
$config[$htConfigCategory][$key] = $a->config[$htConfigCategory][$key];
} }
} else {
$config['config'][$htConfigCategory] = $a->config[$htConfigCategory];
} }
}
unset($a); unset($a);
if (isset($db_host)) { if (isset($db_host)) {
$config['database']['hostname'] = $db_host; $config['database']['hostname'] = $db_host;
unset($db_host); unset($db_host);
} }
if (isset($db_user)) { if (isset($db_user)) {
$config['database']['username'] = $db_user; $config['database']['username'] = $db_user;
unset($db_user); unset($db_user);
} }
if (isset($db_pass)) { if (isset($db_pass)) {
$config['database']['password'] = $db_pass; $config['database']['password'] = $db_pass;
unset($db_pass); unset($db_pass);
} }
if (isset($db_data)) { if (isset($db_data)) {
$config['database']['database'] = $db_data; $config['database']['database'] = $db_data;
unset($db_data); unset($db_data);
} }
if (isset($config['system']['db_charset'])) { if (isset($config['system']) && isset($config['system']['db_charset'])) {
$config['database']['charset'] = $config['system']['db_charset']; $config['database']['charset'] = $config['system']['db_charset'];
} }
if (isset($pidfile)) { if (isset($pidfile)) {
$config['system']['pidfile'] = $pidfile; $config['system']['pidfile'] = $pidfile;
unset($pidfile); unset($pidfile);
} }
if (isset($default_timezone)) { if (isset($default_timezone)) {
$config['system']['default_timezone'] = $default_timezone; $config['system']['default_timezone'] = $default_timezone;
unset($default_timezone); unset($default_timezone);
} }
if (isset($lang)) { if (isset($lang)) {
$config['system']['language'] = $lang; $config['system']['language'] = $lang;
unset($lang); unset($lang);
}
} }
return $config; return $config;