Merge pull request #10693 from nupplaphil/feat/config_dir
Add the possibility to use a different configuration directory
This commit is contained in:
+2
-1
@@ -25,6 +25,7 @@ use Exception;
|
||||
use Friendica\App\Arguments;
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\App\Module;
|
||||
use Friendica\Factory\ConfigFactory;
|
||||
use Friendica\Module\Maintenance;
|
||||
use Friendica\Security\Authentication;
|
||||
use Friendica\Core\Config\Cache;
|
||||
@@ -352,7 +353,7 @@ class App
|
||||
$this->profiler->update($this->config);
|
||||
|
||||
Core\Hook::loadHooks();
|
||||
$loader = new ConfigFileLoader($this->getBasePath());
|
||||
$loader = (new ConfigFactory())->createConfigFileLoader($this->getBasePath(), $_SERVER);
|
||||
Core\Hook::callAll('load_config', $loader);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,45 @@ use Friendica\Util\ConfigFileLoader;
|
||||
|
||||
class ConfigFactory
|
||||
{
|
||||
/**
|
||||
* The key of the $_SERVER variable to override the config directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const CONFIG_DIR_ENV = 'FRIENDICA_CONFIG_DIR';
|
||||
|
||||
/**
|
||||
* The Sub directory of the config-files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const CONFIG_DIR = 'config';
|
||||
|
||||
/**
|
||||
* The Sub directory of the static config-files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const STATIC_DIR = 'static';
|
||||
|
||||
/**
|
||||
* @param string $basePath The basepath of FRIENDICA
|
||||
* @param array $serer the $_SERVER array
|
||||
*
|
||||
* @return ConfigFileLoader
|
||||
*/
|
||||
public function createConfigFileLoader(string $basePath, array $server = [])
|
||||
{
|
||||
if (!empty($server[self::CONFIG_DIR_ENV]) && is_dir($server[self::CONFIG_DIR_ENV])) {
|
||||
$configDir = $server[self::CONFIG_DIR_ENV];
|
||||
} else {
|
||||
$configDir = $basePath . DIRECTORY_SEPARATOR . self::CONFIG_DIR;
|
||||
}
|
||||
$staticDir = $basePath . DIRECTORY_SEPARATOR . self::STATIC_DIR;
|
||||
|
||||
return new ConfigFileLoader($basePath, $configDir, $staticDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
|
||||
*
|
||||
|
||||
@@ -29,6 +29,7 @@ use Friendica\Core\Update;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Factory\ConfigFactory;
|
||||
use Friendica\Model\Register;
|
||||
use Friendica\Module\BaseAdmin;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
@@ -151,7 +152,7 @@ class Summary extends BaseAdmin
|
||||
}
|
||||
|
||||
// check legacy basepath settings
|
||||
$configLoader = new ConfigFileLoader($a->getBasePath());
|
||||
$configLoader = (new ConfigFactory())->createConfigFileLoader($a->getBasePath(), $_SERVER);
|
||||
$configCache = new Cache();
|
||||
$configLoader->setupCache($configCache);
|
||||
$confBasepath = $configCache->get('system', 'basepath');
|
||||
|
||||
@@ -35,20 +35,6 @@ use Friendica\Core\Config\Cache;
|
||||
*/
|
||||
class ConfigFileLoader
|
||||
{
|
||||
/**
|
||||
* The Sub directory of the config-files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const CONFIG_DIR = 'config';
|
||||
|
||||
/**
|
||||
* The Sub directory of the static config-files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const STATIC_DIR = 'static';
|
||||
|
||||
/**
|
||||
* The default name of the user defined ini file
|
||||
*
|
||||
@@ -83,11 +69,16 @@ class ConfigFileLoader
|
||||
*/
|
||||
private $staticDir;
|
||||
|
||||
public function __construct(string $basePath)
|
||||
/**
|
||||
* @param string $baseDir The base
|
||||
* @param string $configDir
|
||||
* @param string $staticDir
|
||||
*/
|
||||
public function __construct(string $baseDir, string $configDir, string $staticDir)
|
||||
{
|
||||
$this->baseDir = $basePath;
|
||||
$this->configDir = $this->baseDir . DIRECTORY_SEPARATOR . self::CONFIG_DIR;
|
||||
$this->staticDir = $this->baseDir . DIRECTORY_SEPARATOR . self::STATIC_DIR;
|
||||
$this->baseDir = $baseDir;
|
||||
$this->configDir = $configDir;
|
||||
$this->staticDir = $staticDir;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +93,7 @@ class ConfigFileLoader
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setupCache(Cache $config, array $server = [], $raw = false)
|
||||
public function setupCache(Cache $config, array $server = [], bool $raw = false)
|
||||
{
|
||||
// Load static config files first, the order is important
|
||||
$config->load($this->loadStaticConfig('defaults'), Cache::SOURCE_FILE);
|
||||
@@ -185,7 +176,7 @@ class ConfigFileLoader
|
||||
$filepath = $this->baseDir . DIRECTORY_SEPARATOR . // /var/www/html/
|
||||
Addon::DIRECTORY . DIRECTORY_SEPARATOR . // addon/
|
||||
$name . DIRECTORY_SEPARATOR . // openstreetmap/
|
||||
self::CONFIG_DIR . DIRECTORY_SEPARATOR . // config/
|
||||
'config'. DIRECTORY_SEPARATOR . // config/
|
||||
$name . ".config.php"; // openstreetmap.config.php
|
||||
|
||||
if (file_exists($filepath)) {
|
||||
@@ -206,9 +197,8 @@ class ConfigFileLoader
|
||||
*/
|
||||
public function loadEnvConfig(array $server)
|
||||
{
|
||||
$filepath = $this->baseDir . DIRECTORY_SEPARATOR . // /var/www/html/
|
||||
self::STATIC_DIR . DIRECTORY_SEPARATOR . // static/
|
||||
"env.config.php"; // env.config.php
|
||||
$filepath = $this->staticDir . DIRECTORY_SEPARATOR . // /var/www/html/static/
|
||||
"env.config.php"; // env.config.php
|
||||
|
||||
if (!file_exists($filepath)) {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user