diff options
author | ArthurHoaro <arthur@hoa.ro> | 2018-07-28 11:07:55 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2018-07-28 11:07:55 +0200 |
commit | 83faedadff76c5bdca036f39f13943f63b27e164 (patch) | |
tree | 6f44cede16ec6a60f10b9699e211e0818f06d2c8 /application/config | |
parent | 1d9eb22a3df85b67fe6652c0876cd7382c2fb525 (diff) | |
parent | 658988f3aeba7a5a938783249ccf2765251e5597 (diff) | |
download | Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.tar.gz Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.tar.zst Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.zip |
Merge tag 'v0.9.7' into stable
Release v0.9.7
Diffstat (limited to 'application/config')
-rw-r--r-- | application/config/ConfigIO.php | 7 | ||||
-rw-r--r-- | application/config/ConfigJson.php | 28 | ||||
-rw-r--r-- | application/config/ConfigManager.php | 73 | ||||
-rw-r--r-- | application/config/ConfigPhp.php | 22 | ||||
-rw-r--r-- | application/config/ConfigPlugin.php | 17 | ||||
-rw-r--r-- | application/config/exception/MissingFieldConfigException.php | 23 | ||||
-rw-r--r-- | application/config/exception/PluginConfigOrderException.php | 17 | ||||
-rw-r--r-- | application/config/exception/UnauthorizedConfigException.php | 18 |
8 files changed, 125 insertions, 80 deletions
diff --git a/application/config/ConfigIO.php b/application/config/ConfigIO.php index 2b68fe6a..3efe5b6f 100644 --- a/application/config/ConfigIO.php +++ b/application/config/ConfigIO.php | |||
@@ -1,4 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Config; | ||
2 | 3 | ||
3 | /** | 4 | /** |
4 | * Interface ConfigIO | 5 | * Interface ConfigIO |
@@ -14,7 +15,7 @@ interface ConfigIO | |||
14 | * | 15 | * |
15 | * @return array All configuration in an array. | 16 | * @return array All configuration in an array. |
16 | */ | 17 | */ |
17 | function read($filepath); | 18 | public function read($filepath); |
18 | 19 | ||
19 | /** | 20 | /** |
20 | * Write configuration. | 21 | * Write configuration. |
@@ -22,12 +23,12 @@ interface ConfigIO | |||
22 | * @param string $filepath Config file absolute path. | 23 | * @param string $filepath Config file absolute path. |
23 | * @param array $conf All configuration in an array. | 24 | * @param array $conf All configuration in an array. |
24 | */ | 25 | */ |
25 | function write($filepath, $conf); | 26 | public function write($filepath, $conf); |
26 | 27 | ||
27 | /** | 28 | /** |
28 | * Get config file extension according to config type. | 29 | * Get config file extension according to config type. |
29 | * | 30 | * |
30 | * @return string Config file extension. | 31 | * @return string Config file extension. |
31 | */ | 32 | */ |
32 | function getExtension(); | 33 | public function getExtension(); |
33 | } | 34 | } |
diff --git a/application/config/ConfigJson.php b/application/config/ConfigJson.php index 30007eb4..8c8d5610 100644 --- a/application/config/ConfigJson.php +++ b/application/config/ConfigJson.php | |||
@@ -1,4 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Config; | ||
2 | 3 | ||
3 | /** | 4 | /** |
4 | * Class ConfigJson (ConfigIO implementation) | 5 | * Class ConfigJson (ConfigIO implementation) |
@@ -10,7 +11,7 @@ class ConfigJson implements ConfigIO | |||
10 | /** | 11 | /** |
11 | * @inheritdoc | 12 | * @inheritdoc |
12 | */ | 13 | */ |
13 | function read($filepath) | 14 | public function read($filepath) |
14 | { | 15 | { |
15 | if (! is_readable($filepath)) { | 16 | if (! is_readable($filepath)) { |
16 | return array(); | 17 | return array(); |
@@ -20,8 +21,19 @@ class ConfigJson implements ConfigIO | |||
20 | $data = str_replace(self::getPhpSuffix(), '', $data); | 21 | $data = str_replace(self::getPhpSuffix(), '', $data); |
21 | $data = json_decode($data, true); | 22 | $data = json_decode($data, true); |
22 | if ($data === null) { | 23 | if ($data === null) { |
23 | $error = json_last_error(); | 24 | $errorCode = json_last_error(); |
24 | throw new Exception('An error occurred while parsing JSON file: error code #'. $error); | 25 | $error = sprintf( |
26 | 'An error occurred while parsing JSON configuration file (%s): error code #%d', | ||
27 | $filepath, | ||
28 | $errorCode | ||
29 | ); | ||
30 | $error .= '<br>➜ <code>' . json_last_error_msg() .'</code>'; | ||
31 | if ($errorCode === JSON_ERROR_SYNTAX) { | ||
32 | $error .= '<br>'; | ||
33 | $error .= 'Please check your JSON syntax (without PHP comment tags) using a JSON lint tool such as '; | ||
34 | $error .= '<a href="http://jsonlint.com/">jsonlint.com</a>.'; | ||
35 | } | ||
36 | throw new \Exception($error); | ||
25 | } | 37 | } |
26 | return $data; | 38 | return $data; |
27 | } | 39 | } |
@@ -29,16 +41,16 @@ class ConfigJson implements ConfigIO | |||
29 | /** | 41 | /** |
30 | * @inheritdoc | 42 | * @inheritdoc |
31 | */ | 43 | */ |
32 | function write($filepath, $conf) | 44 | public function write($filepath, $conf) |
33 | { | 45 | { |
34 | // JSON_PRETTY_PRINT is available from PHP 5.4. | 46 | // JSON_PRETTY_PRINT is available from PHP 5.4. |
35 | $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; | 47 | $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; |
36 | $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); | 48 | $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); |
37 | if (!file_put_contents($filepath, $data)) { | 49 | if (!file_put_contents($filepath, $data)) { |
38 | throw new IOException( | 50 | throw new \IOException( |
39 | $filepath, | 51 | $filepath, |
40 | 'Shaarli could not create the config file. | 52 | t('Shaarli could not create the config file. '. |
41 | Please make sure Shaarli has the right to write in the folder is it installed in.' | 53 | 'Please make sure Shaarli has the right to write in the folder is it installed in.') |
42 | ); | 54 | ); |
43 | } | 55 | } |
44 | } | 56 | } |
@@ -46,7 +58,7 @@ class ConfigJson implements ConfigIO | |||
46 | /** | 58 | /** |
47 | * @inheritdoc | 59 | * @inheritdoc |
48 | */ | 60 | */ |
49 | function getExtension() | 61 | public function getExtension() |
50 | { | 62 | { |
51 | return '.json.php'; | 63 | return '.json.php'; |
52 | } | 64 | } |
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index f5f753f8..9e4c9f63 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php | |||
@@ -1,17 +1,16 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Config; | ||
2 | 3 | ||
3 | // FIXME! Namespaces... | 4 | use Shaarli\Config\Exception\MissingFieldConfigException; |
4 | require_once 'ConfigIO.php'; | 5 | use Shaarli\Config\Exception\UnauthorizedConfigException; |
5 | require_once 'ConfigJson.php'; | ||
6 | require_once 'ConfigPhp.php'; | ||
7 | 6 | ||
8 | /** | 7 | /** |
9 | * Class ConfigManager | 8 | * Class ConfigManager |
10 | * | 9 | * |
11 | * Manages all Shaarli's settings. | 10 | * Manages all Shaarli's settings. |
12 | * See the documentation for more information on settings: | 11 | * See the documentation for more information on settings: |
13 | * - doc/Shaarli-configuration.html | 12 | * - doc/md/Shaarli-configuration.md |
14 | * - https://github.com/shaarli/Shaarli/wiki/Shaarli-configuration | 13 | * - https://shaarli.readthedocs.io/en/master/Shaarli-configuration/#configuration |
15 | */ | 14 | */ |
16 | class ConfigManager | 15 | class ConfigManager |
17 | { | 16 | { |
@@ -20,6 +19,8 @@ class ConfigManager | |||
20 | */ | 19 | */ |
21 | protected static $NOT_FOUND = 'NOT_FOUND'; | 20 | protected static $NOT_FOUND = 'NOT_FOUND'; |
22 | 21 | ||
22 | public static $DEFAULT_PLUGINS = array('qrcode'); | ||
23 | |||
23 | /** | 24 | /** |
24 | * @var string Config folder. | 25 | * @var string Config folder. |
25 | */ | 26 | */ |
@@ -80,7 +81,11 @@ class ConfigManager | |||
80 | */ | 81 | */ |
81 | protected function load() | 82 | protected function load() |
82 | { | 83 | { |
83 | $this->loadedConfig = $this->configIO->read($this->getConfigFileExt()); | 84 | try { |
85 | $this->loadedConfig = $this->configIO->read($this->getConfigFileExt()); | ||
86 | } catch (\Exception $e) { | ||
87 | die($e->getMessage()); | ||
88 | } | ||
84 | $this->setDefaultValues(); | 89 | $this->setDefaultValues(); |
85 | } | 90 | } |
86 | 91 | ||
@@ -122,12 +127,12 @@ class ConfigManager | |||
122 | * @param bool $write Write the new setting in the config file, default false. | 127 | * @param bool $write Write the new setting in the config file, default false. |
123 | * @param bool $isLoggedIn User login state, default false. | 128 | * @param bool $isLoggedIn User login state, default false. |
124 | * | 129 | * |
125 | * @throws Exception Invalid | 130 | * @throws \Exception Invalid |
126 | */ | 131 | */ |
127 | public function set($setting, $value, $write = false, $isLoggedIn = false) | 132 | public function set($setting, $value, $write = false, $isLoggedIn = false) |
128 | { | 133 | { |
129 | if (empty($setting) || ! is_string($setting)) { | 134 | if (empty($setting) || ! is_string($setting)) { |
130 | throw new Exception('Invalid setting key parameter. String expected, got: '. gettype($setting)); | 135 | throw new \Exception(t('Invalid setting key parameter. String expected, got: '). gettype($setting)); |
131 | } | 136 | } |
132 | 137 | ||
133 | // During the ConfigIO transition, map legacy settings to the new ones. | 138 | // During the ConfigIO transition, map legacy settings to the new ones. |
@@ -175,7 +180,7 @@ class ConfigManager | |||
175 | * | 180 | * |
176 | * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. | 181 | * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. |
177 | * @throws UnauthorizedConfigException: user is not authorize to change configuration. | 182 | * @throws UnauthorizedConfigException: user is not authorize to change configuration. |
178 | * @throws IOException: an error occurred while writing the new config file. | 183 | * @throws \IOException: an error occurred while writing the new config file. |
179 | */ | 184 | */ |
180 | public function write($isLoggedIn) | 185 | public function write($isLoggedIn) |
181 | { | 186 | { |
@@ -296,7 +301,9 @@ class ConfigManager | |||
296 | $this->setEmpty('resource.updates', 'data/updates.txt'); | 301 | $this->setEmpty('resource.updates', 'data/updates.txt'); |
297 | $this->setEmpty('resource.log', 'data/log.txt'); | 302 | $this->setEmpty('resource.log', 'data/log.txt'); |
298 | $this->setEmpty('resource.update_check', 'data/lastupdatecheck.txt'); | 303 | $this->setEmpty('resource.update_check', 'data/lastupdatecheck.txt'); |
304 | $this->setEmpty('resource.history', 'data/history.php'); | ||
299 | $this->setEmpty('resource.raintpl_tpl', 'tpl/'); | 305 | $this->setEmpty('resource.raintpl_tpl', 'tpl/'); |
306 | $this->setEmpty('resource.theme', 'default'); | ||
300 | $this->setEmpty('resource.raintpl_tmp', 'tmp/'); | 307 | $this->setEmpty('resource.raintpl_tmp', 'tmp/'); |
301 | $this->setEmpty('resource.thumbnails_cache', 'cache'); | 308 | $this->setEmpty('resource.thumbnails_cache', 'cache'); |
302 | $this->setEmpty('resource.page_cache', 'pagecache'); | 309 | $this->setEmpty('resource.page_cache', 'pagecache'); |
@@ -305,21 +312,26 @@ class ConfigManager | |||
305 | $this->setEmpty('security.ban_duration', 1800); | 312 | $this->setEmpty('security.ban_duration', 1800); |
306 | $this->setEmpty('security.session_protection_disabled', false); | 313 | $this->setEmpty('security.session_protection_disabled', false); |
307 | $this->setEmpty('security.open_shaarli', false); | 314 | $this->setEmpty('security.open_shaarli', false); |
315 | $this->setEmpty('security.allowed_protocols', ['ftp', 'ftps', 'magnet']); | ||
308 | 316 | ||
309 | $this->setEmpty('general.header_link', '?'); | 317 | $this->setEmpty('general.header_link', '?'); |
310 | $this->setEmpty('general.links_per_page', 20); | 318 | $this->setEmpty('general.links_per_page', 20); |
311 | $this->setEmpty('general.enabled_plugins', array('qrcode')); | 319 | $this->setEmpty('general.enabled_plugins', self::$DEFAULT_PLUGINS); |
320 | $this->setEmpty('general.default_note_title', 'Note: '); | ||
312 | 321 | ||
313 | $this->setEmpty('updates.check_updates', false); | 322 | $this->setEmpty('updates.check_updates', false); |
314 | $this->setEmpty('updates.check_updates_branch', 'stable'); | 323 | $this->setEmpty('updates.check_updates_branch', 'stable'); |
315 | $this->setEmpty('updates.check_updates_interval', 86400); | 324 | $this->setEmpty('updates.check_updates_interval', 86400); |
316 | 325 | ||
317 | $this->setEmpty('feed.rss_permalinks', true); | 326 | $this->setEmpty('feed.rss_permalinks', true); |
318 | $this->setEmpty('feed.show_atom', false); | 327 | $this->setEmpty('feed.show_atom', true); |
319 | 328 | ||
320 | $this->setEmpty('privacy.default_private_links', false); | 329 | $this->setEmpty('privacy.default_private_links', false); |
321 | $this->setEmpty('privacy.hide_public_links', false); | 330 | $this->setEmpty('privacy.hide_public_links', false); |
331 | $this->setEmpty('privacy.force_login', false); | ||
322 | $this->setEmpty('privacy.hide_timestamps', false); | 332 | $this->setEmpty('privacy.hide_timestamps', false); |
333 | // default state of the 'remember me' checkbox of the login form | ||
334 | $this->setEmpty('privacy.remember_user_default', true); | ||
323 | 335 | ||
324 | $this->setEmpty('thumbnail.enable_thumbnails', true); | 336 | $this->setEmpty('thumbnail.enable_thumbnails', true); |
325 | $this->setEmpty('thumbnail.enable_localcache', true); | 337 | $this->setEmpty('thumbnail.enable_localcache', true); |
@@ -327,6 +339,10 @@ class ConfigManager | |||
327 | $this->setEmpty('redirector.url', ''); | 339 | $this->setEmpty('redirector.url', ''); |
328 | $this->setEmpty('redirector.encode_url', true); | 340 | $this->setEmpty('redirector.encode_url', true); |
329 | 341 | ||
342 | $this->setEmpty('translation.language', 'auto'); | ||
343 | $this->setEmpty('translation.mode', 'php'); | ||
344 | $this->setEmpty('translation.extensions', []); | ||
345 | |||
330 | $this->setEmpty('plugins', array()); | 346 | $this->setEmpty('plugins', array()); |
331 | } | 347 | } |
332 | 348 | ||
@@ -359,36 +375,3 @@ class ConfigManager | |||
359 | $this->configIO = $configIO; | 375 | $this->configIO = $configIO; |
360 | } | 376 | } |
361 | } | 377 | } |
362 | |||
363 | /** | ||
364 | * Exception used if a mandatory field is missing in given configuration. | ||
365 | */ | ||
366 | class MissingFieldConfigException extends Exception | ||
367 | { | ||
368 | public $field; | ||
369 | |||
370 | /** | ||
371 | * Construct exception. | ||
372 | * | ||
373 | * @param string $field field name missing. | ||
374 | */ | ||
375 | public function __construct($field) | ||
376 | { | ||
377 | $this->field = $field; | ||
378 | $this->message = 'Configuration value is required for '. $this->field; | ||
379 | } | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * Exception used if an unauthorized attempt to edit configuration has been made. | ||
384 | */ | ||
385 | class UnauthorizedConfigException extends Exception | ||
386 | { | ||
387 | /** | ||
388 | * Construct exception. | ||
389 | */ | ||
390 | public function __construct() | ||
391 | { | ||
392 | $this->message = 'You are not authorized to alter config.'; | ||
393 | } | ||
394 | } | ||
diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php index 27187b66..8add8bcd 100644 --- a/application/config/ConfigPhp.php +++ b/application/config/ConfigPhp.php | |||
@@ -1,4 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Config; | ||
2 | 3 | ||
3 | /** | 4 | /** |
4 | * Class ConfigPhp (ConfigIO implementation) | 5 | * Class ConfigPhp (ConfigIO implementation) |
@@ -41,6 +42,7 @@ class ConfigPhp implements ConfigIO | |||
41 | 'resource.log' => 'config.LOG_FILE', | 42 | 'resource.log' => 'config.LOG_FILE', |
42 | 'resource.update_check' => 'config.UPDATECHECK_FILENAME', | 43 | 'resource.update_check' => 'config.UPDATECHECK_FILENAME', |
43 | 'resource.raintpl_tpl' => 'config.RAINTPL_TPL', | 44 | 'resource.raintpl_tpl' => 'config.RAINTPL_TPL', |
45 | 'resource.theme' => 'config.theme', | ||
44 | 'resource.raintpl_tmp' => 'config.RAINTPL_TMP', | 46 | 'resource.raintpl_tmp' => 'config.RAINTPL_TMP', |
45 | 'resource.thumbnails_cache' => 'config.CACHEDIR', | 47 | 'resource.thumbnails_cache' => 'config.CACHEDIR', |
46 | 'resource.page_cache' => 'config.PAGECACHE', | 48 | 'resource.page_cache' => 'config.PAGECACHE', |
@@ -71,7 +73,7 @@ class ConfigPhp implements ConfigIO | |||
71 | /** | 73 | /** |
72 | * @inheritdoc | 74 | * @inheritdoc |
73 | */ | 75 | */ |
74 | function read($filepath) | 76 | public function read($filepath) |
75 | { | 77 | { |
76 | if (! file_exists($filepath) || ! is_readable($filepath)) { | 78 | if (! file_exists($filepath) || ! is_readable($filepath)) { |
77 | return array(); | 79 | return array(); |
@@ -81,17 +83,17 @@ class ConfigPhp implements ConfigIO | |||
81 | 83 | ||
82 | $out = array(); | 84 | $out = array(); |
83 | foreach (self::$ROOT_KEYS as $key) { | 85 | foreach (self::$ROOT_KEYS as $key) { |
84 | $out[$key] = $GLOBALS[$key]; | 86 | $out[$key] = isset($GLOBALS[$key]) ? $GLOBALS[$key] : ''; |
85 | } | 87 | } |
86 | $out['config'] = $GLOBALS['config']; | 88 | $out['config'] = isset($GLOBALS['config']) ? $GLOBALS['config'] : []; |
87 | $out['plugins'] = !empty($GLOBALS['plugins']) ? $GLOBALS['plugins'] : array(); | 89 | $out['plugins'] = isset($GLOBALS['plugins']) ? $GLOBALS['plugins'] : []; |
88 | return $out; | 90 | return $out; |
89 | } | 91 | } |
90 | 92 | ||
91 | /** | 93 | /** |
92 | * @inheritdoc | 94 | * @inheritdoc |
93 | */ | 95 | */ |
94 | function write($filepath, $conf) | 96 | public function write($filepath, $conf) |
95 | { | 97 | { |
96 | $configStr = '<?php '. PHP_EOL; | 98 | $configStr = '<?php '. PHP_EOL; |
97 | foreach (self::$ROOT_KEYS as $key) { | 99 | foreach (self::$ROOT_KEYS as $key) { |
@@ -99,7 +101,7 @@ class ConfigPhp implements ConfigIO | |||
99 | $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL; | 101 | $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL; |
100 | } | 102 | } |
101 | } | 103 | } |
102 | 104 | ||
103 | // Store all $conf['config'] | 105 | // Store all $conf['config'] |
104 | foreach ($conf['config'] as $key => $value) { | 106 | foreach ($conf['config'] as $key => $value) { |
105 | $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL; | 107 | $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL; |
@@ -114,10 +116,10 @@ class ConfigPhp implements ConfigIO | |||
114 | if (!file_put_contents($filepath, $configStr) | 116 | if (!file_put_contents($filepath, $configStr) |
115 | || strcmp(file_get_contents($filepath), $configStr) != 0 | 117 | || strcmp(file_get_contents($filepath), $configStr) != 0 |
116 | ) { | 118 | ) { |
117 | throw new IOException( | 119 | throw new \IOException( |
118 | $filepath, | 120 | $filepath, |
119 | 'Shaarli could not create the config file. | 121 | t('Shaarli could not create the config file. '. |
120 | Please make sure Shaarli has the right to write in the folder is it installed in.' | 122 | 'Please make sure Shaarli has the right to write in the folder is it installed in.') |
121 | ); | 123 | ); |
122 | } | 124 | } |
123 | } | 125 | } |
@@ -125,7 +127,7 @@ class ConfigPhp implements ConfigIO | |||
125 | /** | 127 | /** |
126 | * @inheritdoc | 128 | * @inheritdoc |
127 | */ | 129 | */ |
128 | function getExtension() | 130 | public function getExtension() |
129 | { | 131 | { |
130 | return '.php'; | 132 | return '.php'; |
131 | } | 133 | } |
diff --git a/application/config/ConfigPlugin.php b/application/config/ConfigPlugin.php index cb0b6fce..b3d9752b 100644 --- a/application/config/ConfigPlugin.php +++ b/application/config/ConfigPlugin.php | |||
@@ -1,4 +1,7 @@ | |||
1 | <?php | 1 | <?php |
2 | |||
3 | use Shaarli\Config\Exception\PluginConfigOrderException; | ||
4 | |||
2 | /** | 5 | /** |
3 | * Plugin configuration helper functions. | 6 | * Plugin configuration helper functions. |
4 | * | 7 | * |
@@ -108,17 +111,3 @@ function load_plugin_parameter_values($plugins, $conf) | |||
108 | 111 | ||
109 | return $out; | 112 | return $out; |
110 | } | 113 | } |
111 | |||
112 | /** | ||
113 | * Exception used if an error occur while saving plugin configuration. | ||
114 | */ | ||
115 | class PluginConfigOrderException extends Exception | ||
116 | { | ||
117 | /** | ||
118 | * Construct exception. | ||
119 | */ | ||
120 | public function __construct() | ||
121 | { | ||
122 | $this->message = 'An error occurred while trying to save plugins loading order.'; | ||
123 | } | ||
124 | } | ||
diff --git a/application/config/exception/MissingFieldConfigException.php b/application/config/exception/MissingFieldConfigException.php new file mode 100644 index 00000000..9e0a9359 --- /dev/null +++ b/application/config/exception/MissingFieldConfigException.php | |||
@@ -0,0 +1,23 @@ | |||
1 | <?php | ||
2 | |||
3 | |||
4 | namespace Shaarli\Config\Exception; | ||
5 | |||
6 | /** | ||
7 | * Exception used if a mandatory field is missing in given configuration. | ||
8 | */ | ||
9 | class MissingFieldConfigException extends \Exception | ||
10 | { | ||
11 | public $field; | ||
12 | |||
13 | /** | ||
14 | * Construct exception. | ||
15 | * | ||
16 | * @param string $field field name missing. | ||
17 | */ | ||
18 | public function __construct($field) | ||
19 | { | ||
20 | $this->field = $field; | ||
21 | $this->message = sprintf(t('Configuration value is required for %s'), $this->field); | ||
22 | } | ||
23 | } | ||
diff --git a/application/config/exception/PluginConfigOrderException.php b/application/config/exception/PluginConfigOrderException.php new file mode 100644 index 00000000..f82ec26e --- /dev/null +++ b/application/config/exception/PluginConfigOrderException.php | |||
@@ -0,0 +1,17 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Shaarli\Config\Exception; | ||
4 | |||
5 | /** | ||
6 | * Exception used if an error occur while saving plugin configuration. | ||
7 | */ | ||
8 | class PluginConfigOrderException extends \Exception | ||
9 | { | ||
10 | /** | ||
11 | * Construct exception. | ||
12 | */ | ||
13 | public function __construct() | ||
14 | { | ||
15 | $this->message = t('An error occurred while trying to save plugins loading order.'); | ||
16 | } | ||
17 | } | ||
diff --git a/application/config/exception/UnauthorizedConfigException.php b/application/config/exception/UnauthorizedConfigException.php new file mode 100644 index 00000000..72311fae --- /dev/null +++ b/application/config/exception/UnauthorizedConfigException.php | |||
@@ -0,0 +1,18 @@ | |||
1 | <?php | ||
2 | |||
3 | |||
4 | namespace Shaarli\Config\Exception; | ||
5 | |||
6 | /** | ||
7 | * Exception used if an unauthorized attempt to edit configuration has been made. | ||
8 | */ | ||
9 | class UnauthorizedConfigException extends \Exception | ||
10 | { | ||
11 | /** | ||
12 | * Construct exception. | ||
13 | */ | ||
14 | public function __construct() | ||
15 | { | ||
16 | $this->message = t('You are not authorized to alter config.'); | ||
17 | } | ||
18 | } | ||