Dynamic config loading
- Move settings, defaults and dbstructure to directory 'static' - Dynamic loading of config files (after the static loading) - Filter out '-sample.config.php' and '-sample.ini.php' files - Remove unnecessary ConfigFileManager - Move ConfigFileLoader to Utils - Add tests for multi-loading for INI, config and sample-filtering
This commit is contained in:
parent
966043712f
commit
92fb0a82ca
25 changed files with 325 additions and 161 deletions
|
@ -21,33 +21,34 @@ trait VFSTrait
|
|||
$structure = [
|
||||
'config' => [],
|
||||
'bin' => [],
|
||||
'test' => []
|
||||
'static' => [],
|
||||
'test' => [],
|
||||
];
|
||||
|
||||
// create a virtual directory and copy all needed files and folders to it
|
||||
$this->root = vfsStream::setup('friendica', 0777, $structure);
|
||||
|
||||
$this->setConfigFile('defaults.config.php');
|
||||
$this->setConfigFile('settings.config.php');
|
||||
$this->setConfigFile('defaults.config.php', true);
|
||||
$this->setConfigFile('settings.config.php', true);
|
||||
$this->setConfigFile('local.config.php');
|
||||
$this->setConfigFile('dbstructure.config.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Copying a config file from the file system to the Virtual File System
|
||||
*
|
||||
* @param string $filename The filename of the config file
|
||||
* @param bool $static True, if the folder `static` instead of `config` should be used
|
||||
*/
|
||||
protected function setConfigFile($filename)
|
||||
protected function setConfigFile($filename, bool $static = false)
|
||||
{
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'config' . DIRECTORY_SEPARATOR .
|
||||
($static ? 'static' : 'config') . DIRECTORY_SEPARATOR .
|
||||
$filename;
|
||||
|
||||
if (file_exists($file)) {
|
||||
vfsStream::newFile($filename)
|
||||
->at($this->root->getChild('config'))
|
||||
->at($this->root->getChild(($static ? 'static' : 'config')))
|
||||
->setContent(file_get_contents($file));
|
||||
}
|
||||
}
|
||||
|
@ -56,11 +57,12 @@ trait VFSTrait
|
|||
* Delets a config file from the Virtual File System
|
||||
*
|
||||
* @param string $filename The filename of the config file
|
||||
* @param bool $static True, if the folder `static` instead of `config` should be used
|
||||
*/
|
||||
protected function delConfigFile($filename)
|
||||
protected function delConfigFile($filename, bool $static = false)
|
||||
{
|
||||
if ($this->root->hasChild('config/' . $filename)) {
|
||||
$this->root->getChild('config')->removeChild($filename);
|
||||
if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) {
|
||||
$this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue