aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/config/ConfigManager.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/config/ConfigManager.php')
-rw-r--r--application/config/ConfigManager.php49
1 files changed, 45 insertions, 4 deletions
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
@@ -63,15 +63,24 @@ class ConfigManager
63 } 63 }
64 64
65 /** 65 /**
66 * Reset the ConfigManager instance.
67 */
68 public static function reset()
69 {
70 self::$instance = null;
71 return self::getInstance();
72 }
73
74 /**
66 * Rebuild the loaded config array from config files. 75 * Rebuild the loaded config array from config files.
67 */ 76 */
68 public function reload() 77 public function reload()
69 { 78 {
70 $this->initialize(); 79 $this->load();
71 } 80 }
72 81
73 /** 82 /**
74 * Initialize loaded conf in ConfigManager. 83 * Initialize the ConfigIO and loaded the conf.
75 */ 84 */
76 protected function initialize() 85 protected function initialize()
77 { 86 {
@@ -81,7 +90,15 @@ class ConfigManager
81 $this->configIO = new ConfigPhp(); 90 $this->configIO = new ConfigPhp();
82 }*/ 91 }*/
83 $this->configIO = new ConfigPhp(); 92 $this->configIO = new ConfigPhp();
84 $this->loadedConfig = $this->configIO->read(self::$CONFIG_FILE); 93 $this->load();
94 }
95
96 /**
97 * Load configuration in the ConfigurationManager.
98 */
99 protected function load()
100 {
101 $this->loadedConfig = $this->configIO->read($this->getConfigFile());
85 $this->setDefaultValues(); 102 $this->setDefaultValues();
86 } 103 }
87 104
@@ -117,9 +134,15 @@ class ConfigManager
117 * @param string $value Value to set. 134 * @param string $value Value to set.
118 * @param bool $write Write the new setting in the config file, default false. 135 * @param bool $write Write the new setting in the config file, default false.
119 * @param bool $isLoggedIn User login state, default false. 136 * @param bool $isLoggedIn User login state, default false.
137 *
138 * @throws Exception Invalid
120 */ 139 */
121 public function set($setting, $value, $write = false, $isLoggedIn = false) 140 public function set($setting, $value, $write = false, $isLoggedIn = false)
122 { 141 {
142 if (empty($setting) || ! is_string($setting)) {
143 throw new Exception('Invalid setting key parameter. String expected, got: '. gettype($setting));
144 }
145
123 $settings = explode('.', $setting); 146 $settings = explode('.', $setting);
124 self::setConfig($settings, $value, $this->loadedConfig); 147 self::setConfig($settings, $value, $this->loadedConfig);
125 if ($write) { 148 if ($write) {
@@ -151,6 +174,8 @@ class ConfigManager
151 * 174 *
152 * @param bool $isLoggedIn User login state. 175 * @param bool $isLoggedIn User login state.
153 * 176 *
177 * @return bool True if the configuration has been successfully written, false otherwise.
178 *
154 * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. 179 * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf.
155 * @throws UnauthorizedConfigException: user is not authorize to change configuration. 180 * @throws UnauthorizedConfigException: user is not authorize to change configuration.
156 * @throws IOException: an error occurred while writing the new config file. 181 * @throws IOException: an error occurred while writing the new config file.
@@ -175,7 +200,7 @@ class ConfigManager
175 } 200 }
176 } 201 }
177 202
178 $this->configIO->write(self::$CONFIG_FILE, $this->loadedConfig); 203 return $this->configIO->write($this->getConfigFile(), $this->loadedConfig);
179 } 204 }
180 205
181 /** 206 /**
@@ -327,6 +352,22 @@ class ConfigManager
327 $this->set($key, $value); 352 $this->set($key, $value);
328 } 353 }
329 } 354 }
355
356 /**
357 * @return ConfigIO
358 */
359 public function getConfigIO()
360 {
361 return $this->configIO;
362 }
363
364 /**
365 * @param ConfigIO $configIO
366 */
367 public function setConfigIO($configIO)
368 {
369 $this->configIO = $configIO;
370 }
330} 371}
331 372
332/** 373/**