]> git.mxchange.org Git - friendica.git/commitdiff
Refactor ConfigFileManager
authorArt4 <art4@wlabs.de>
Tue, 19 Nov 2024 07:48:43 +0000 (07:48 +0000)
committerArt4 <art4@wlabs.de>
Tue, 19 Nov 2024 07:48:43 +0000 (07:48 +0000)
src/Core/Config/Util/ConfigFileManager.php

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