*/
private $staticDir;
+ /**
+ * @var array
+ */
+ private $server;
+
/**
* @param string $baseDir The base
* @param string $configDir
* @param string $staticDir
*/
- public function __construct(string $baseDir, string $configDir, string $staticDir)
+ public function __construct(string $baseDir, string $configDir, string $staticDir, array $server = [])
{
$this->baseDir = $baseDir;
$this->configDir = $configDir;
$this->staticDir = $staticDir;
+ $this->server = $server;
}
/**
* expected local.config.php
*
* @param Cache $config The config cache to load to
- * @param array $server The $_SERVER array
* @param bool $raw Set up the raw config format
*
* @throws ConfigFileException
*/
- public function setupCache(Cache $config, array $server = [], bool $raw = false)
+ public function setupCache(Cache $config, bool $raw = false)
{
// Load static config files first, the order is important
$config->load($this->loadStaticConfig('defaults'), Cache::SOURCE_STATIC);
// Now load the node.config.php file with the node specific config values (based on admin gui/console actions)
$this->loadDataConfig($config);
- $config->load($this->loadEnvConfig($server), Cache::SOURCE_ENV);
+ $config->load($this->loadEnvConfig(), Cache::SOURCE_ENV);
// In case of install mode, add the found basepath (because there isn't a basepath set yet
if (!$raw && empty($config->get('system', 'basepath'))) {
/**
* Tries to load environment specific variables, based on the `env.config.php` mapping table
*
- * @param array $server The $_SERVER variable
- *
* @return array The config array (empty if no config was found)
*
* @throws ConfigFileException if the configuration file isn't readable
*/
- public function loadEnvConfig(array $server): array
+ protected function loadEnvConfig(): array
{
$filepath = $this->staticDir . DIRECTORY_SEPARATOR . // /var/www/html/static/
"env.config.php"; // env.config.php
$return = [];
foreach ($envConfig as $envKey => $configStructure) {
- if (isset($server[$envKey])) {
- $return[$configStructure[0]][$configStructure[1]] = $server[$envKey];
+ if (isset($this->server[$envKey])) {
+ $return[$configStructure[0]][$configStructure[1]] = $this->server[$envKey];
}
}
$sampleEnd = self::SAMPLE_END . ($ini ? '.ini.php' : '.config.php');
foreach ($files as $filename) {
- if (fnmatch($filePattern, $filename) && substr_compare($filename, $sampleEnd, -strlen($sampleEnd))) {
+ if (fnmatch($filePattern, $filename) &&
+ substr_compare($filename, $sampleEnd, -strlen($sampleEnd)) &&
+ $filename !== self::CONFIG_DATA_FILE) {
$found[] = $this->configDir . '/' . $filename;
}
}
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
);
+
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
$this->delConfigFile('local.config.php');
vfsStream::newFile('local.config.php')
- ->at($this->root->getChild('config'))
- ->setContent('<?php return true;');
+ ->at($this->root->getChild('config'))
+ ->setContent('<?php return true;');
$configFileLoader = new ConfigFileManager(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
);
- $configCache = new Cache();
+ $configCache = new Cache();
$configFileLoader->setupCache($configCache);
}
$this->delConfigFile('local.config.php');
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- 'datasets' . DIRECTORY_SEPARATOR .
- 'config' . DIRECTORY_SEPARATOR .
- 'A.config.php';
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ 'datasets' . DIRECTORY_SEPARATOR .
+ 'config' . DIRECTORY_SEPARATOR .
+ 'A.config.php';
vfsStream::newFile('local.config.php')
- ->at($this->root->getChild('config'))
- ->setContent(file_get_contents($file));
+ ->at($this->root->getChild('config'))
+ ->setContent(file_get_contents($file));
$configFileLoader = new ConfigFileManager(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
);
- $configCache = new Cache();
+ $configCache = new Cache();
$configFileLoader->setupCache($configCache);
$this->delConfigFile('local.config.php');
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- 'datasets' . DIRECTORY_SEPARATOR .
- 'config' . DIRECTORY_SEPARATOR .
- 'A.ini.php';
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ 'datasets' . DIRECTORY_SEPARATOR .
+ 'config' . DIRECTORY_SEPARATOR .
+ 'A.ini.php';
vfsStream::newFile('local.ini.php')
- ->at($this->root->getChild('config'))
- ->setContent(file_get_contents($file));
+ ->at($this->root->getChild('config'))
+ ->setContent(file_get_contents($file));
$configFileLoader = new ConfigFileManager(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
);
- $configCache = new Cache();
+ $configCache = new Cache();
$configFileLoader->setupCache($configCache);
$this->delConfigFile('local.config.php');
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- 'datasets' . DIRECTORY_SEPARATOR .
- 'config' . DIRECTORY_SEPARATOR .
- '.htconfig.php';
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ 'datasets' . DIRECTORY_SEPARATOR .
+ 'config' . DIRECTORY_SEPARATOR .
+ '.htconfig.php';
vfsStream::newFile('.htconfig.php')
- ->at($this->root)
- ->setContent(file_get_contents($file));
+ ->at($this->root)
+ ->setContent(file_get_contents($file));
$configFileLoader = new ConfigFileManager(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
);
- $configCache = new Cache();
+ $configCache = new Cache();
$configFileLoader->setupCache($configCache);
vfsStream::create($structure, $this->root);
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- 'datasets' . DIRECTORY_SEPARATOR .
- 'config' . DIRECTORY_SEPARATOR .
- 'A.config.php';
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ 'datasets' . DIRECTORY_SEPARATOR .
+ 'config' . DIRECTORY_SEPARATOR .
+ 'A.config.php';
vfsStream::newFile('test.config.php')
- ->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
- ->setContent(file_get_contents($file));
+ ->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
+ ->setContent(file_get_contents($file));
$configFileLoader = new ConfigFileManager(
$this->root->url(),
$this->delConfigFile('local.config.php');
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- 'datasets' . DIRECTORY_SEPARATOR .
- 'config' . DIRECTORY_SEPARATOR;
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ 'datasets' . DIRECTORY_SEPARATOR .
+ 'config' . DIRECTORY_SEPARATOR;
vfsStream::newFile('A.config.php')
- ->at($this->root->getChild('config'))
- ->setContent(file_get_contents($fileDir . 'A.config.php'));
+ ->at($this->root->getChild('config'))
+ ->setContent(file_get_contents($fileDir . 'A.config.php'));
vfsStream::newFile('B.config.php')
- ->at($this->root->getChild('config'))
- ->setContent(file_get_contents($fileDir . 'B.config.php'));
+ ->at($this->root->getChild('config'))
+ ->setContent(file_get_contents($fileDir . 'B.config.php'));
$configFileLoader = new ConfigFileManager(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
);
- $configCache = new Cache();
+ $configCache = new Cache();
$configFileLoader->setupCache($configCache);
$this->delConfigFile('local.config.php');
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
- 'datasets' . DIRECTORY_SEPARATOR .
- 'config' . DIRECTORY_SEPARATOR;
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ 'datasets' . DIRECTORY_SEPARATOR .
+ 'config' . DIRECTORY_SEPARATOR;
vfsStream::newFile('A.ini.php')
- ->at($this->root->getChild('config'))
- ->setContent(file_get_contents($fileDir . 'A.ini.php'));
+ ->at($this->root->getChild('config'))
+ ->setContent(file_get_contents($fileDir . 'A.ini.php'));
vfsStream::newFile('B.ini.php')
- ->at($this->root->getChild('config'))
- ->setContent(file_get_contents($fileDir . 'B.ini.php'));
+ ->at($this->root->getChild('config'))
+ ->setContent(file_get_contents($fileDir . 'B.ini.php'));
$configFileLoader = new ConfigFileManager(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
);
- $configCache = new Cache();
+ $configCache = new Cache();
$configFileLoader->setupCache($configCache);
$this->delConfigFile('local.config.php');
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
- '..' . DIRECTORY_SEPARATOR .
- 'datasets' . DIRECTORY_SEPARATOR .
- 'config' . DIRECTORY_SEPARATOR;
+ '..' . DIRECTORY_SEPARATOR .
+ '..' . DIRECTORY_SEPARATOR .
+ 'datasets' . DIRECTORY_SEPARATOR .
+ 'config' . DIRECTORY_SEPARATOR;
vfsStream::newFile('A.ini.php')
- ->at($this->root->getChild('config'))
- ->setContent(file_get_contents($fileDir . 'A.ini.php'));
+ ->at($this->root->getChild('config'))
+ ->setContent(file_get_contents($fileDir . 'A.ini.php'));
vfsStream::newFile('B-sample.ini.php')
- ->at($this->root->getChild('config'))
- ->setContent(file_get_contents($fileDir . 'B.ini.php'));
+ ->at($this->root->getChild('config'))
+ ->setContent(file_get_contents($fileDir . 'B.ini.php'));
$configFileLoader = new ConfigFileManager(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
);
+
$configCache = new Cache();
$configFileLoader->setupCache($configCache);
{
$this->delConfigFile('local.config.php');
- $configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
- $configCache = new Cache();
+ $configFileManager = (new Config())->createConfigFileManager($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
+ $configCache = new Cache();
- $configFileLoader->setupCache($configCache);
+ $configFileManager->setupCache($configCache);
self::assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
}
->at($this->root->getChild('config2'))
->setContent(file_get_contents($fileDir . 'B.config.php'));
- $configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
- $configCache = new Cache();
+ $configFileManager = (new Config())->createConfigFileManager($this->root->url(),
+ [
+ 'FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url(),
+ ]);
+ $configCache = new Cache();
- $configFileLoader->setupCache($configCache);
+ $configFileManager->setupCache($configCache);
self::assertEquals('newValue', $configCache->get('system', 'newKey'));
}
->at($this->root->getChild('config2'))
->setContent(file_get_contents($fileDir . 'B.config.php'));
- $configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
- $configCache = new Cache();
+ $configFileManager = (new Config())->createConfigFileManager($this->root->url(),
+ [
+ 'FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url(),
+ ]);
+ $configCache = new Cache();
- $configFileLoader->setupCache($configCache);
+ $configFileManager->setupCache($configCache);
$specialChars = '!"§$%&/()(/&%$\'><?$a,;:[]}{}\\?¿¿ß';
$configCache->set('config', 'test', 'it', Cache::SOURCE_DATA);
$configCache->set('system', 'test_2', 2, Cache::SOURCE_DATA);
$configCache->set('special_chars', 'special', $specialChars, Cache::SOURCE_DATA);
- $configFileLoader->saveData($configCache);
+ $configFileManager->saveData($configCache);
// Reload the configCache with the new values
$configCache2 = new Cache();
- $configFileLoader->setupCache($configCache2);
+ $configFileManager->setupCache($configCache2);
self::assertEquals($configCache, $configCache2);
self::assertEquals([
- 'system' => [
- 'test' => 'it',
+ 'system' => [
+ 'test' => 'it',
'test_2' => 2
],
- 'config' => [
+ 'config' => [
'test' => 'it',
],
'special_chars' => [