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;
$this->profiler->update($this->config);
Core\Hook::loadHooks();
- $loader = new ConfigFileLoader($this->getBasePath(), $_SERVER);
+ $loader = (new ConfigFactory())->createConfigFileLoader($this->getBasePath(), $_SERVER);
Core\Hook::callAll('load_config', $loader);
}
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)
*
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;
}
// check legacy basepath settings
- $configLoader = new ConfigFileLoader($a->getBasePath(), $_SERVER);
+ $configLoader = (new ConfigFactory())->createConfigFileLoader($a->getBasePath(), $_SERVER);
$configCache = new Cache();
$configLoader->setupCache($configCache);
$confBasepath = $configCache->get('system', 'basepath');
*/
class ConfigFileLoader
{
- /**
- * 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';
-
/**
* The default name of the user defined ini file
*
*/
private $staticDir;
- public function __construct(string $basePath, array $server)
+ /**
+ * @param string $baseDir The base
+ * @param string $configDir
+ * @param string $staticDir
+ */
+ public function __construct(string $baseDir, string $configDir, string $staticDir)
{
- $this->baseDir = $basePath;
- if (!empty($server[self::CONFIG_DIR_ENV]) && is_dir($server[self::CONFIG_DIR_ENV])) {
- $this->configDir = $server[self::CONFIG_DIR_ENV];
- } else {
- $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;
}
/**
*
* @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);
$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)) {
*/
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 [];
]
],
Util\ConfigFileLoader::class => [
- 'shared' => true,
- 'constructParams' => [
- [Dice::INSTANCE => '$basepath'],
- $_SERVER,
+ 'instanceOf' => Factory\ConfigFactory::class,
+ 'call' => [
+ ['createConfigFileLoader', [
+ [Dice::INSTANCE => '$basepath'],
+ $_SERVER,
+ ], Dice::CHAIN_CALL],
],
],
Config\Cache::class => [
// load real config to avoid mocking every config-entry which is related to the Database class
$configFactory = new ConfigFactory();
- $loader = new ConfigFileLoader($this->root->url(), []);
+ $loader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), []);
$configCache = $configFactory->createCache($loader);
$dba = new StaticDatabase($configCache, $profiler, $logger);
// load real config to avoid mocking every config-entry which is related to the Database class
$configFactory = new ConfigFactory();
- $loader = new ConfigFileLoader($this->root->url(), []);
+ $loader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), []);
$configCache = $configFactory->createCache($loader);
$dba = new StaticDatabase($configCache, $profiler, $logger);
// load real config to avoid mocking every config-entry which is related to the Database class
$configFactory = new ConfigFactory();
- $loader = new ConfigFileLoader($this->root->url(), []);
+ $loader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), []);
$configCache = $configFactory->createCache($loader);
$this->dba = new StaticDatabase($configCache, $profiler, $logger);
// load real config to avoid mocking every config-entry which is related to the Database class
$configFactory = new ConfigFactory();
- $loader = new ConfigFileLoader($this->root->url(), []);
+ $loader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), []);
$configCache = $configFactory->createCache($loader);
$dba = new StaticDatabase($configCache, $profiler, $logger);
namespace Friendica\Test\src\Util\Config;
use Friendica\Core\Config\Cache;
+use Friendica\Factory\ConfigFactory;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\ConfigFileLoader;
{
$this->delConfigFile('local.config.php');
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
->at($this->root->getChild('config'))
->setContent('<?php return true;');
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
->at($this->root->getChild('config'))
->setContent(file_get_contents($file));
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
->at($this->root->getChild('config'))
->setContent(file_get_contents($file));
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
->at($this->root)
->setContent(file_get_contents($file));
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
->setContent(file_get_contents($file));
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$conf = $configFileLoader->loadAddonConfig('test');
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'B.config.php'));
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'B.ini.php'));
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'B.ini.php'));
- $configFileLoader = new ConfigFileLoader($this->root->url(), []);
+ $configFileLoader = new ConfigFileLoader(
+ $this->root->url(),
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
+ $this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
+ );
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
{
$this->delConfigFile('local.config.php');
- $configFileLoader = new ConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
+ $configFileLoader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
->at($this->root->getChild('config2'))
->setContent(file_get_contents($fileDir . 'B.config.php'));
- $configFileLoader = new ConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
+ $configFileLoader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
$configCache = new Cache();
$configFileLoader->setupCache($configCache);