aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/ApplicationUtils.php26
-rw-r--r--application/Config.php221
-rw-r--r--application/FileUtils.php8
-rw-r--r--application/PageBuilder.php28
-rw-r--r--application/Updater.php30
-rw-r--r--application/Utils.php2
-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
10 files changed, 98 insertions, 275 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php
index 978fc9da..ed9abc39 100644
--- a/application/ApplicationUtils.php
+++ b/application/ApplicationUtils.php
@@ -132,32 +132,32 @@ class ApplicationUtils
132 /** 132 /**
133 * Checks Shaarli has the proper access permissions to its resources 133 * Checks Shaarli has the proper access permissions to its resources
134 * 134 *
135 * @param array $globalConfig The $GLOBALS['config'] array
136 *
137 * @return array A list of the detected configuration issues 135 * @return array A list of the detected configuration issues
138 */ 136 */
139 public static function checkResourcePermissions($globalConfig) 137 public static function checkResourcePermissions()
140 { 138 {
141 $errors = array(); 139 $errors = array();
140 $conf = ConfigManager::getInstance();
142 141
143 // Check script and template directories are readable 142 // Check script and template directories are readable
144 foreach (array( 143 foreach (array(
145 'application', 144 'application',
146 'inc', 145 'inc',
147 'plugins', 146 'plugins',
148 $globalConfig['RAINTPL_TPL'] 147 $conf->get('config.RAINTPL_TPL'),
149 ) as $path) { 148 ) as $path) {
150 if (! is_readable(realpath($path))) { 149 if (! is_readable(realpath($path))) {
151 $errors[] = '"'.$path.'" directory is not readable'; 150 $errors[] = '"'.$path.'" directory is not readable';
152 } 151 }
153 } 152 }
154 153
154 $datadir = $conf->get('config.DATADIR');
155 // Check cache and data directories are readable and writeable 155 // Check cache and data directories are readable and writeable
156 foreach (array( 156 foreach (array(
157 $globalConfig['CACHEDIR'], 157 $conf->get('config.CACHEDIR'),
158 $globalConfig['DATADIR'], 158 $datadir,
159 $globalConfig['PAGECACHE'], 159 $conf->get('config.PAGECACHE'),
160 $globalConfig['RAINTPL_TMP'] 160 $conf->get('config.RAINTPL_TMP'),
161 ) as $path) { 161 ) as $path) {
162 if (! is_readable(realpath($path))) { 162 if (! is_readable(realpath($path))) {
163 $errors[] = '"'.$path.'" directory is not readable'; 163 $errors[] = '"'.$path.'" directory is not readable';
@@ -169,11 +169,11 @@ class ApplicationUtils
169 169
170 // Check configuration files are readable and writeable 170 // Check configuration files are readable and writeable
171 foreach (array( 171 foreach (array(
172 $globalConfig['CONFIG_FILE'], 172 $conf->getConfigFile(),
173 $globalConfig['DATASTORE'], 173 $conf->get('config.DATASTORE'),
174 $globalConfig['IPBANS_FILENAME'], 174 $conf->get('config.IPBANS_FILENAME'),
175 $globalConfig['LOG_FILE'], 175 $conf->get('config.LOG_FILE'),
176 $globalConfig['UPDATECHECK_FILENAME'] 176 $conf->get('config.UPDATECHECK_FILENAME'),
177 ) as $path) { 177 ) as $path) {
178 if (! is_file(realpath($path))) { 178 if (! is_file(realpath($path))) {
179 # the file may not exist yet 179 # the file may not exist yet
diff --git a/application/Config.php b/application/Config.php
deleted file mode 100644
index 05a59452..00000000
--- a/application/Config.php
+++ /dev/null
@@ -1,221 +0,0 @@
1<?php
2/**
3 * Functions related to configuration management.
4 */
5
6/**
7 * Re-write configuration file according to given array.
8 * Requires mandatory fields listed in $MANDATORY_FIELDS.
9 *
10 * @param array $config contains all configuration fields.
11 * @param bool $isLoggedIn true if user is logged in.
12 *
13 * @return void
14 *
15 * @throws MissingFieldConfigException: a mandatory field has not been provided in $config.
16 * @throws UnauthorizedConfigException: user is not authorize to change configuration.
17 * @throws Exception: an error occured while writing the new config file.
18 */
19function writeConfig($config, $isLoggedIn)
20{
21 // These fields are required in configuration.
22 $MANDATORY_FIELDS = array(
23 'login', 'hash', 'salt', 'timezone', 'title', 'titleLink',
24 'redirector', 'disablesessionprotection', 'privateLinkByDefault'
25 );
26
27 if (!isset($config['config']['CONFIG_FILE'])) {
28 throw new MissingFieldConfigException('CONFIG_FILE');
29 }
30
31 // Only logged in user can alter config.
32 if (is_file($config['config']['CONFIG_FILE']) && !$isLoggedIn) {
33 throw new UnauthorizedConfigException();
34 }
35
36 // Check that all mandatory fields are provided in $config.
37 foreach ($MANDATORY_FIELDS as $field) {
38 if (!isset($config[$field])) {
39 throw new MissingFieldConfigException($field);
40 }
41 }
42
43 $configStr = '<?php '. PHP_EOL;
44 $configStr .= '$GLOBALS[\'login\'] = '.var_export($config['login'], true).';'. PHP_EOL;
45 $configStr .= '$GLOBALS[\'hash\'] = '.var_export($config['hash'], true).';'. PHP_EOL;
46 $configStr .= '$GLOBALS[\'salt\'] = '.var_export($config['salt'], true).'; '. PHP_EOL;
47 $configStr .= '$GLOBALS[\'timezone\'] = '.var_export($config['timezone'], true).';'. PHP_EOL;
48 $configStr .= 'date_default_timezone_set('.var_export($config['timezone'], true).');'. PHP_EOL;
49 $configStr .= '$GLOBALS[\'title\'] = '.var_export($config['title'], true).';'. PHP_EOL;
50 $configStr .= '$GLOBALS[\'titleLink\'] = '.var_export($config['titleLink'], true).'; '. PHP_EOL;
51 $configStr .= '$GLOBALS[\'redirector\'] = '.var_export($config['redirector'], true).'; '. PHP_EOL;
52 $configStr .= '$GLOBALS[\'disablesessionprotection\'] = '.var_export($config['disablesessionprotection'], true).'; '. PHP_EOL;
53 $configStr .= '$GLOBALS[\'privateLinkByDefault\'] = '.var_export($config['privateLinkByDefault'], true).'; '. PHP_EOL;
54
55 // Store all $config['config']
56 foreach ($config['config'] as $key => $value) {
57 $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($config['config'][$key], true).';'. PHP_EOL;
58 }
59
60 if (isset($config['plugins'])) {
61 foreach ($config['plugins'] as $key => $value) {
62 $configStr .= '$GLOBALS[\'plugins\'][\''. $key .'\'] = '.var_export($config['plugins'][$key], true).';'. PHP_EOL;
63 }
64 }
65
66 if (!file_put_contents($config['config']['CONFIG_FILE'], $configStr)
67 || strcmp(file_get_contents($config['config']['CONFIG_FILE']), $configStr) != 0
68 ) {
69 throw new Exception(
70 'Shaarli could not create the config file.
71 Please make sure Shaarli has the right to write in the folder is it installed in.'
72 );
73 }
74}
75
76/**
77 * Process plugin administration form data and save it in an array.
78 *
79 * @param array $formData Data sent by the plugin admin form.
80 *
81 * @return array New list of enabled plugin, ordered.
82 *
83 * @throws PluginConfigOrderException Plugins can't be sorted because their order is invalid.
84 */
85function save_plugin_config($formData)
86{
87 // Make sure there are no duplicates in orders.
88 if (!validate_plugin_order($formData)) {
89 throw new PluginConfigOrderException();
90 }
91
92 $plugins = array();
93 $newEnabledPlugins = array();
94 foreach ($formData as $key => $data) {
95 if (startsWith($key, 'order')) {
96 continue;
97 }
98
99 // If there is no order, it means a disabled plugin has been enabled.
100 if (isset($formData['order_' . $key])) {
101 $plugins[(int) $formData['order_' . $key]] = $key;
102 }
103 else {
104 $newEnabledPlugins[] = $key;
105 }
106 }
107
108 // New enabled plugins will be added at the end of order.
109 $plugins = array_merge($plugins, $newEnabledPlugins);
110
111 // Sort plugins by order.
112 if (!ksort($plugins)) {
113 throw new PluginConfigOrderException();
114 }
115
116 $finalPlugins = array();
117 // Make plugins order continuous.
118 foreach ($plugins as $plugin) {
119 $finalPlugins[] = $plugin;
120 }
121
122 return $finalPlugins;
123}
124
125/**
126 * Validate plugin array submitted.
127 * Will fail if there is duplicate orders value.
128 *
129 * @param array $formData Data from submitted form.
130 *
131 * @return bool true if ok, false otherwise.
132 */
133function validate_plugin_order($formData)
134{
135 $orders = array();
136 foreach ($formData as $key => $value) {
137 // No duplicate order allowed.
138 if (in_array($value, $orders)) {
139 return false;
140 }
141
142 if (startsWith($key, 'order')) {
143 $orders[] = $value;
144 }
145 }
146
147 return true;
148}
149
150/**
151 * Affect plugin parameters values into plugins array.
152 *
153 * @param mixed $plugins Plugins array ($plugins[<plugin_name>]['parameters']['param_name'] = <value>.
154 * @param mixed $config Plugins configuration.
155 *
156 * @return mixed Updated $plugins array.
157 */
158function load_plugin_parameter_values($plugins, $config)
159{
160 $out = $plugins;
161 foreach ($plugins as $name => $plugin) {
162 if (empty($plugin['parameters'])) {
163 continue;
164 }
165
166 foreach ($plugin['parameters'] as $key => $param) {
167 if (!empty($config[$key])) {
168 $out[$name]['parameters'][$key] = $config[$key];
169 }
170 }
171 }
172
173 return $out;
174}
175
176/**
177 * Exception used if a mandatory field is missing in given configuration.
178 */
179class MissingFieldConfigException extends Exception
180{
181 public $field;
182
183 /**
184 * Construct exception.
185 *
186 * @param string $field field name missing.
187 */
188 public function __construct($field)
189 {
190 $this->field = $field;
191 $this->message = 'Configuration value is required for '. $this->field;
192 }
193}
194
195/**
196 * Exception used if an unauthorized attempt to edit configuration has been made.
197 */
198class UnauthorizedConfigException extends Exception
199{
200 /**
201 * Construct exception.
202 */
203 public function __construct()
204 {
205 $this->message = 'You are not authorized to alter config.';
206 }
207}
208
209/**
210 * Exception used if an error occur while saving plugin configuration.
211 */
212class PluginConfigOrderException extends Exception
213{
214 /**
215 * Construct exception.
216 */
217 public function __construct()
218 {
219 $this->message = 'An error occurred while trying to save plugins loading order.';
220 }
221}
diff --git a/application/FileUtils.php b/application/FileUtils.php
index 6a12ef0e..6cac9825 100644
--- a/application/FileUtils.php
+++ b/application/FileUtils.php
@@ -9,11 +9,13 @@ class IOException extends Exception
9 /** 9 /**
10 * Construct a new IOException 10 * Construct a new IOException
11 * 11 *
12 * @param string $path path to the ressource that cannot be accessed 12 * @param string $path path to the resource that cannot be accessed
13 * @param string $message Custom exception message.
13 */ 14 */
14 public function __construct($path) 15 public function __construct($path, $message = '')
15 { 16 {
16 $this->path = $path; 17 $this->path = $path;
17 $this->message = 'Error accessing '.$this->path; 18 $this->message = empty($message) ? 'Error accessing' : $message;
19 $this->message .= PHP_EOL . $this->path;
18 } 20 }
19} 21}
diff --git a/application/PageBuilder.php b/application/PageBuilder.php
index 82580787..cf13c714 100644
--- a/application/PageBuilder.php
+++ b/application/PageBuilder.php
@@ -29,21 +29,22 @@ class PageBuilder
29 private function initialize() 29 private function initialize()
30 { 30 {
31 $this->tpl = new RainTPL(); 31 $this->tpl = new RainTPL();
32 $conf = ConfigManager::getInstance();
32 33
33 try { 34 try {
34 $version = ApplicationUtils::checkUpdate( 35 $version = ApplicationUtils::checkUpdate(
35 shaarli_version, 36 shaarli_version,
36 $GLOBALS['config']['UPDATECHECK_FILENAME'], 37 $conf->get('config.UPDATECHECK_FILENAME'),
37 $GLOBALS['config']['UPDATECHECK_INTERVAL'], 38 $conf->get('config.UPDATECHECK_INTERVAL'),
38 $GLOBALS['config']['ENABLE_UPDATECHECK'], 39 $conf->get('config.ENABLE_UPDATECHECK'),
39 isLoggedIn(), 40 isLoggedIn(),
40 $GLOBALS['config']['UPDATECHECK_BRANCH'] 41 $conf->get('config.UPDATECHECK_BRANCH')
41 ); 42 );
42 $this->tpl->assign('newVersion', escape($version)); 43 $this->tpl->assign('newVersion', escape($version));
43 $this->tpl->assign('versionError', ''); 44 $this->tpl->assign('versionError', '');
44 45
45 } catch (Exception $exc) { 46 } catch (Exception $exc) {
46 logm($GLOBALS['config']['LOG_FILE'], $_SERVER['REMOTE_ADDR'], $exc->getMessage()); 47 logm($conf->get('config.LOG_FILE'), $_SERVER['REMOTE_ADDR'], $exc->getMessage());
47 $this->tpl->assign('newVersion', ''); 48 $this->tpl->assign('newVersion', '');
48 $this->tpl->assign('versionError', escape($exc->getMessage())); 49 $this->tpl->assign('versionError', escape($exc->getMessage()));
49 } 50 }
@@ -62,16 +63,19 @@ class PageBuilder
62 $this->tpl->assign('scripturl', index_url($_SERVER)); 63 $this->tpl->assign('scripturl', index_url($_SERVER));
63 $this->tpl->assign('pagetitle', 'Shaarli'); 64 $this->tpl->assign('pagetitle', 'Shaarli');
64 $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? 65 $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
65 if (!empty($GLOBALS['title'])) { 66 if ($conf->exists('title')) {
66 $this->tpl->assign('pagetitle', $GLOBALS['title']); 67 $this->tpl->assign('pagetitle', $conf->get('title'));
67 } 68 }
68 if (!empty($GLOBALS['titleLink'])) { 69 if ($conf->exists('titleLink')) {
69 $this->tpl->assign('titleLink', $GLOBALS['titleLink']); 70 $this->tpl->assign('titleLink', $conf->get('titleLink'));
70 } 71 }
71 if (!empty($GLOBALS['pagetitle'])) { 72 if ($conf->exists('pagetitle')) {
72 $this->tpl->assign('pagetitle', $GLOBALS['pagetitle']); 73 $this->tpl->assign('pagetitle', $conf->get('pagetitle'));
73 } 74 }
74 $this->tpl->assign('shaarlititle', empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title']); 75 $this->tpl->assign('shaarlititle', $conf->get('title', 'Shaarli'));
76 $this->tpl->assign('openshaarli', $conf->get('config.OPEN_SHAARLI', false));
77 $this->tpl->assign('showatom', $conf->get('config.SHOW_ATOM', false));
78 // FIXME! Globals
75 if (!empty($GLOBALS['plugin_errors'])) { 79 if (!empty($GLOBALS['plugin_errors'])) {
76 $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); 80 $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']);
77 } 81 }
diff --git a/application/Updater.php b/application/Updater.php
index 58c13c07..6b92af3d 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -13,11 +13,6 @@ class Updater
13 protected $doneUpdates; 13 protected $doneUpdates;
14 14
15 /** 15 /**
16 * @var array Shaarli's configuration array.
17 */
18 protected $config;
19
20 /**
21 * @var LinkDB instance. 16 * @var LinkDB instance.
22 */ 17 */
23 protected $linkDB; 18 protected $linkDB;
@@ -36,14 +31,12 @@ class Updater
36 * Object constructor. 31 * Object constructor.
37 * 32 *
38 * @param array $doneUpdates Updates which are already done. 33 * @param array $doneUpdates Updates which are already done.
39 * @param array $config Shaarli's configuration array.
40 * @param LinkDB $linkDB LinkDB instance. 34 * @param LinkDB $linkDB LinkDB instance.
41 * @param boolean $isLoggedIn True if the user is logged in. 35 * @param boolean $isLoggedIn True if the user is logged in.
42 */ 36 */
43 public function __construct($doneUpdates, $config, $linkDB, $isLoggedIn) 37 public function __construct($doneUpdates, $linkDB, $isLoggedIn)
44 { 38 {
45 $this->doneUpdates = $doneUpdates; 39 $this->doneUpdates = $doneUpdates;
46 $this->config = $config;
47 $this->linkDB = $linkDB; 40 $this->linkDB = $linkDB;
48 $this->isLoggedIn = $isLoggedIn; 41 $this->isLoggedIn = $isLoggedIn;
49 42
@@ -114,19 +107,21 @@ class Updater
114 */ 107 */
115 public function updateMethodMergeDeprecatedConfigFile() 108 public function updateMethodMergeDeprecatedConfigFile()
116 { 109 {
117 $config_file = $this->config['config']['CONFIG_FILE']; 110 $conf = ConfigManager::getInstance();
118 111
119 if (is_file($this->config['config']['DATADIR'].'/options.php')) { 112 if (is_file($conf->get('config.DATADIR') . '/options.php')) {
120 include $this->config['config']['DATADIR'].'/options.php'; 113 include $conf->get('config.DATADIR') . '/options.php';
121 114
122 // Load GLOBALS into config 115 // Load GLOBALS into config
116 $allowedKeys = array_merge(ConfigPhp::$ROOT_KEYS);
117 $allowedKeys[] = 'config';
123 foreach ($GLOBALS as $key => $value) { 118 foreach ($GLOBALS as $key => $value) {
124 $this->config[$key] = $value; 119 if (in_array($key, $allowedKeys)) {
120 $conf->set($key, $value);
121 }
125 } 122 }
126 $this->config['config']['CONFIG_FILE'] = $config_file; 123 $conf->write($this->isLoggedIn);
127 writeConfig($this->config, $this->isLoggedIn); 124 unlink($conf->get('config.DATADIR').'/options.php');
128
129 unlink($this->config['config']['DATADIR'].'/options.php');
130 } 125 }
131 126
132 return true; 127 return true;
@@ -137,13 +132,14 @@ class Updater
137 */ 132 */
138 public function updateMethodRenameDashTags() 133 public function updateMethodRenameDashTags()
139 { 134 {
135 $conf = ConfigManager::getInstance();
140 $linklist = $this->linkDB->filterSearch(); 136 $linklist = $this->linkDB->filterSearch();
141 foreach ($linklist as $link) { 137 foreach ($linklist as $link) {
142 $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); 138 $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']);
143 $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); 139 $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true)));
144 $this->linkDB[$link['linkdate']] = $link; 140 $this->linkDB[$link['linkdate']] = $link;
145 } 141 }
146 $this->linkDB->savedb($this->config['config']['PAGECACHE']); 142 $this->linkDB->savedb($conf->get('config.PAGECACHE'));
147 return true; 143 return true;
148 } 144 }
149} 145}
diff --git a/application/Utils.php b/application/Utils.php
index da521cce..9a8ca6d1 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -273,4 +273,4 @@ function autoLocale($headerLocale)
273 } 273 }
274 } 274 }
275 setlocale(LC_ALL, $attempts); 275 setlocale(LC_ALL, $attempts);
276} \ No newline at end of file 276}
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/**