X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fconfig%2FConfigManager.php;h=212aac050a26dde34ce18e069009d9d570e9534f;hb=684e662a58b02bde225e44d3677987b6fc3adf0b;hp=dfe9eeb964872047bd54525f78c170245c7ecdc9;hpb=59404d7909b21682ec0782778452a8a70e38b25e;p=github%2Fshaarli%2FShaarli.git diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index dfe9eeb9..212aac05 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php @@ -62,16 +62,25 @@ class ConfigManager return self::$instance; } + /** + * Reset the ConfigManager instance. + */ + public static function reset() + { + self::$instance = null; + return self::getInstance(); + } + /** * Rebuild the loaded config array from config files. */ public function reload() { - $this->initialize(); + $this->load(); } /** - * Initialize loaded conf in ConfigManager. + * Initialize the ConfigIO and loaded the conf. */ protected function initialize() { @@ -81,7 +90,15 @@ class ConfigManager $this->configIO = new ConfigPhp(); }*/ $this->configIO = new ConfigPhp(); - $this->loadedConfig = $this->configIO->read(self::$CONFIG_FILE); + $this->load(); + } + + /** + * Load configuration in the ConfigurationManager. + */ + protected function load() + { + $this->loadedConfig = $this->configIO->read($this->getConfigFile()); $this->setDefaultValues(); } @@ -117,9 +134,15 @@ class ConfigManager * @param string $value Value to set. * @param bool $write Write the new setting in the config file, default false. * @param bool $isLoggedIn User login state, default false. + * + * @throws Exception Invalid */ public function set($setting, $value, $write = false, $isLoggedIn = false) { + if (empty($setting) || ! is_string($setting)) { + throw new Exception('Invalid setting key parameter. String expected, got: '. gettype($setting)); + } + $settings = explode('.', $setting); self::setConfig($settings, $value, $this->loadedConfig); if ($write) { @@ -151,6 +174,8 @@ class ConfigManager * * @param bool $isLoggedIn User login state. * + * @return bool True if the configuration has been successfully written, false otherwise. + * * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. * @throws UnauthorizedConfigException: user is not authorize to change configuration. * @throws IOException: an error occurred while writing the new config file. @@ -175,7 +200,7 @@ class ConfigManager } } - $this->configIO->write(self::$CONFIG_FILE, $this->loadedConfig); + return $this->configIO->write($this->getConfigFile(), $this->loadedConfig); } /** @@ -327,6 +352,22 @@ class ConfigManager $this->set($key, $value); } } + + /** + * @return ConfigIO + */ + public function getConfigIO() + { + return $this->configIO; + } + + /** + * @param ConfigIO $configIO + */ + public function setConfigIO($configIO) + { + $this->configIO = $configIO; + } } /**