aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/config
diff options
context:
space:
mode:
Diffstat (limited to 'application/config')
-rw-r--r--application/config/ConfigIO.php2
-rw-r--r--application/config/ConfigManager.php49
-rw-r--r--application/config/ConfigPhp.php3
-rw-r--r--application/config/ConfigPlugin.php4
4 files changed, 50 insertions, 8 deletions
diff --git a/application/config/ConfigIO.php b/application/config/ConfigIO.php
index 2b68fe6a..4b1c9901 100644
--- a/application/config/ConfigIO.php
+++ b/application/config/ConfigIO.php
@@ -21,6 +21,8 @@ interface ConfigIO
21 * 21 *
22 * @param string $filepath Config file absolute path. 22 * @param string $filepath Config file absolute path.
23 * @param array $conf All configuration in an array. 23 * @param array $conf All configuration in an array.
24 *
25 * @return bool True if the configuration has been successfully written, false otherwise.
24 */ 26 */
25 function write($filepath, $conf); 27 function write($filepath, $conf);
26 28
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/**
diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php
index 311aeb81..19fecf2b 100644
--- a/application/config/ConfigPhp.php
+++ b/application/config/ConfigPhp.php
@@ -28,7 +28,6 @@ class ConfigPhp implements ConfigIO
28 */ 28 */
29 function read($filepath) 29 function read($filepath)
30 { 30 {
31 $filepath .= $this->getExtension();
32 if (! file_exists($filepath) || ! is_readable($filepath)) { 31 if (! file_exists($filepath) || ! is_readable($filepath)) {
33 return array(); 32 return array();
34 } 33 }
@@ -49,8 +48,6 @@ class ConfigPhp implements ConfigIO
49 */ 48 */
50 function write($filepath, $conf) 49 function write($filepath, $conf)
51 { 50 {
52 $filepath .= $this->getExtension();
53
54 $configStr = '<?php '. PHP_EOL; 51 $configStr = '<?php '. PHP_EOL;
55 foreach (self::$ROOT_KEYS as $key) { 52 foreach (self::$ROOT_KEYS as $key) {
56 if (isset($conf[$key])) { 53 if (isset($conf[$key])) {
diff --git a/application/config/ConfigPlugin.php b/application/config/ConfigPlugin.php
index 8af89d04..047d2b03 100644
--- a/application/config/ConfigPlugin.php
+++ b/application/config/ConfigPlugin.php
@@ -1,6 +1,8 @@
1<?php 1<?php
2/** 2/**
3 * Functions related to configuration management. 3 * Plugin configuration helper functions.
4 *
5 * Note: no access to configuration files here.
4 */ 6 */
5 7
6/** 8/**