3 namespace Friendica\Core\Config;
5 class ConfigCacheLoader
10 public function __construct($baseDir)
12 $this->baseDir = $baseDir;
13 $this->configDir = $baseDir . '/config/';
17 * Load the configuration files
19 * First loads the default value for all the configuration keys, then the legacy configuration files, then the
20 * expected local.config.php
22 public function loadConfigFiles(ConfigCache $config)
24 // Setting at least the basepath we know
25 $config->set('system', 'basepath', $this->baseDir);
27 $config->loadConfigArray($this->loadConfigFile('defaults'));
28 $config->loadConfigArray($this->loadConfigFile('settings'));
30 // Legacy .htconfig.php support
31 if (file_exists($this->baseDir . '/.htpreconfig.php')) {
33 include $this->baseDir . '/.htpreconfig.php';
36 // Legacy .htconfig.php support
37 if (file_exists($this->baseDir . '/.htconfig.php')) {
40 include $this->baseDir . '/.htconfig.php';
42 $config->set('database', 'hostname', $db_host);
43 $config->set('database', 'username', $db_user);
44 $config->set('database', 'password', $db_pass);
45 $config->set('database', 'database', $db_data);
46 $charset = $config->get('system', 'db_charset');
47 if (isset($charset)) {
48 $config->set('database', 'charset', $charset);
51 unset($db_host, $db_user, $db_pass, $db_data);
53 if (isset($default_timezone)) {
54 $config->set('system', 'default_timezone', $default_timezone);
55 unset($default_timezone);
58 if (isset($pidfile)) {
59 $config->set('system', 'pidfile', $pidfile);
64 $config->set('system', 'language', $lang);
69 if (file_exists($this->baseDir . '/config/local.config.php')) {
70 $config->loadConfigArray($this->loadConfigFile('local'), true);
71 } elseif (file_exists($this->baseDir . '/config/local.ini.php')) {
72 $config->loadConfigArray($this->loadINIConfigFile('local'), true);
77 * Tries to load the specified legacy configuration file into the App->config array.
78 * Doesn't overwrite previously set values by default to prevent default config files to supersede DB Config.
80 * @deprecated since version 2018.12
81 * @param string $filename
83 * @return array The configuration
86 public function loadINIConfigFile($filename)
88 $filepath = $this->configDir . $filename . ".ini.php";
90 if (!file_exists($filepath)) {
91 throw new \Exception('Error parsing non-existent INI config file ' . $filepath);
94 $contents = include($filepath);
96 $config = parse_ini_string($contents, true, INI_SCANNER_TYPED);
98 if ($config === false) {
99 throw new \Exception('Error parsing INI config file ' . $filepath);
106 * Tries to load the specified configuration file into the App->config array.
107 * Doesn't overwrite previously set values by default to prevent default config files to supersede DB Config.
109 * The config format is PHP array and the template for configuration files is the following:
117 * @param string $filename
118 * @return array The configuration
121 public function loadConfigFile($filename)
123 $filepath = $this->configDir . $filename . ".config.php";
125 if (!file_exists($filepath)) {
126 throw new \Exception('Error loading non-existent config file ' . $filepath);
129 $config = include($filepath);
131 if (!is_array($config)) {
132 throw new \Exception('Error loading config file ' . $filepath);
139 * Loads addons configuration files
141 * First loads all activated addons default configuration through the load_config hook, then load the local.config.php
142 * again to overwrite potential local addon configuration.
144 * @return array The config array
148 public function loadAddonConfig()
150 // Load the local addon config file to overwritten default addon config values
151 if (file_exists($this->configDir . 'addon.config.php')) {
152 return $this->loadConfigFile('addon');
153 } elseif (file_exists($this->configDir . 'addon.ini.php')) {
154 return $this->loadINIConfigFile('addon');