openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit f4f93f48036bf39596148cd0aec1cc4da083d054
parent f7e84a9676a40baa8e407d200ec2bab58d85b196
Author: Jan Dankert <devnull@localhost>
Date:   Tue,  4 Sep 2018 22:39:36 +0200

Der ConfigurationLoader bekommt die Konfigurationsdatei von außen reingereicht, damit das Modul unabhängig wird.

Diffstat:
modules/cms-core/Dispatcher.class.php | 13++++++++-----
modules/configuration/ConfigurationLoader.class.php | 25++++++++++++++++++-------
2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/modules/cms-core/Dispatcher.class.php b/modules/cms-core/Dispatcher.class.php @@ -46,14 +46,15 @@ class Dispatcher $this->checkConfiguration(); + // Vorhandene Konfiguration aus der Sitzung lesen. + global $conf; + $conf = Session::getConfig(); + define('PRODUCTION', Conf()->is('production')); define('DEVELOPMENT', !PRODUCTION); $this->setContentLanguageHeader(); - // Vorhandene Konfiguration aus der Sitzung lesen. - global $conf; - $conf = Session::getConfig(); // Nachdem die Konfiguration gelesen wurde, kann nun der Logger benutzt werden. @@ -197,7 +198,9 @@ class Dispatcher // Konfiguration lesen. // Wenn Konfiguration noch nicht in Session vorhanden oder die Konfiguration geändert wurde (erkennbar anhand des Datei-Datums) // dann die Konfiguration neu einlesen. - if (!is_array($conf) || $conf['config']['auto_reload'] && ConfigurationLoader::lastModificationTime() > $conf['config']['last_modification_time']) { + $configLoader = new ConfigurationLoader( __DIR__.'/../../config/config.yml' ); + + if (!is_array($conf) || $conf['config']['auto_reload'] && $configLoader->lastModificationTime() > $conf['config']['last_modification_time']) { // Da die Konfiguration neu eingelesen wird, sollten wir auch die Sitzung komplett leeren. if (is_array($conf) && $conf['config']['session_destroy_on_config_reload']) @@ -207,7 +210,7 @@ class Dispatcher require(OR_MODULES_DIR . 'util/config-default.php'); $conf = createDefaultConfig(); - $customConfig = ConfigurationLoader::load(); + $customConfig = $configLoader->load(); $conf = array_replace_recursive($conf, $customConfig); diff --git a/modules/configuration/ConfigurationLoader.class.php b/modules/configuration/ConfigurationLoader.class.php @@ -11,16 +11,27 @@ */ class ConfigurationLoader { - public static $configFile = __DIR__.'/../../config/config.yml'; + public $configFile; + + + /* + * Erzeugt eine neue Instanz. + */ + public function __construct( $configFile ) + { + $this->configFile = $configFile; + } + + /** * Ermittelt den Zeitpunkt der letzten Änderung der Konfigurationsdatei. * * @return int Zeitpunkt der letzten Änderung als Unix-Timestamp */ - public static function lastModificationTime() + public function lastModificationTime() { - return filemtime(self::$configFile); + return filemtime($this->configFile); } @@ -29,9 +40,9 @@ class ConfigurationLoader * * @return array Configuration */ - public static function load() + public function load() { - $customConfig = ConfigurationLoader::loadCustomConfig(self::$configFile); + $customConfig = ConfigurationLoader::loadCustomConfig($this->configFile); // Resolve dot-notated configuration keys to arrays. @@ -72,7 +83,7 @@ class ConfigurationLoader * * @return array Configuration */ - private static function loadCustomConfig( $configFile ) + private function loadCustomConfig( $configFile ) { if (!is_file($configFile) && !is_link($configFile)) { error_log('Warning: Configuration file ' . $configFile . ' not found'); @@ -120,7 +131,7 @@ class ConfigurationLoader * @param $value String Configuration value * @return String */ - private static function resolveVariables($value) + private function resolveVariables($value) { return preg_replace_callback( "|\\$\{([[:alnum:]]+)\:([[:alnum:]_]+)\}|",