diff options
-rw-r--r-- | application/config/ConfigManager.php | 36 | ||||
-rw-r--r-- | application/config/exception/MissingFieldConfigException.php | 23 | ||||
-rw-r--r-- | application/config/exception/UnauthorizedConfigException.php | 18 | ||||
-rw-r--r-- | tests/config/ConfigManagerTest.php | 2 |
4 files changed, 45 insertions, 34 deletions
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index 679a75b3..f2097410 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php | |||
@@ -1,6 +1,9 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Config; | 2 | namespace Shaarli\Config; |
3 | 3 | ||
4 | use Shaarli\Config\Exception\MissingFieldConfigException; | ||
5 | use Shaarli\Config\Exception\UnauthorizedConfigException; | ||
6 | |||
4 | /** | 7 | /** |
5 | * Class ConfigManager | 8 | * Class ConfigManager |
6 | * | 9 | * |
@@ -358,36 +361,3 @@ class ConfigManager | |||
358 | $this->configIO = $configIO; | 361 | $this->configIO = $configIO; |
359 | } | 362 | } |
360 | } | 363 | } |
361 | |||
362 | /** | ||
363 | * Exception used if a mandatory field is missing in given configuration. | ||
364 | */ | ||
365 | class MissingFieldConfigException extends \Exception | ||
366 | { | ||
367 | public $field; | ||
368 | |||
369 | /** | ||
370 | * Construct exception. | ||
371 | * | ||
372 | * @param string $field field name missing. | ||
373 | */ | ||
374 | public function __construct($field) | ||
375 | { | ||
376 | $this->field = $field; | ||
377 | $this->message = 'Configuration value is required for '. $this->field; | ||
378 | } | ||
379 | } | ||
380 | |||
381 | /** | ||
382 | * Exception used if an unauthorized attempt to edit configuration has been made. | ||
383 | */ | ||
384 | class UnauthorizedConfigException extends \Exception | ||
385 | { | ||
386 | /** | ||
387 | * Construct exception. | ||
388 | */ | ||
389 | public function __construct() | ||
390 | { | ||
391 | $this->message = 'You are not authorized to alter config.'; | ||
392 | } | ||
393 | } | ||
diff --git a/application/config/exception/MissingFieldConfigException.php b/application/config/exception/MissingFieldConfigException.php new file mode 100644 index 00000000..6346c6a9 --- /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 = 'Configuration value is required for '. $this->field; | ||
22 | } | ||
23 | } | ||
diff --git a/application/config/exception/UnauthorizedConfigException.php b/application/config/exception/UnauthorizedConfigException.php new file mode 100644 index 00000000..79672c1b --- /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 = 'You are not authorized to alter config.'; | ||
17 | } | ||
18 | } | ||
diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index b81be5b6..1ec447b2 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php | |||
@@ -106,7 +106,7 @@ class ConfigManagerTest extends \PHPUnit_Framework_TestCase | |||
106 | /** | 106 | /** |
107 | * Try to write the config without mandatory parameter (e.g. 'login'). | 107 | * Try to write the config without mandatory parameter (e.g. 'login'). |
108 | * | 108 | * |
109 | * @expectedException Shaarli\Config\MissingFieldConfigException | 109 | * @expectedException Shaarli\Config\Exception\MissingFieldConfigException |
110 | */ | 110 | */ |
111 | public function testWriteMissingParameter() | 111 | public function testWriteMissingParameter() |
112 | { | 112 | { |