Move config exception to dedicated classes with proper namespace
This commit is contained in:
parent
9c5daad19c
commit
5ba55f0cf2
4 changed files with 45 additions and 34 deletions
|
@ -1,6 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Shaarli\Config;
|
namespace Shaarli\Config;
|
||||||
|
|
||||||
|
use Shaarli\Config\Exception\MissingFieldConfigException;
|
||||||
|
use Shaarli\Config\Exception\UnauthorizedConfigException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ConfigManager
|
* Class ConfigManager
|
||||||
*
|
*
|
||||||
|
@ -358,36 +361,3 @@ public function setConfigIO($configIO)
|
||||||
$this->configIO = $configIO;
|
$this->configIO = $configIO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception used if a mandatory field is missing in given configuration.
|
|
||||||
*/
|
|
||||||
class MissingFieldConfigException extends \Exception
|
|
||||||
{
|
|
||||||
public $field;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct exception.
|
|
||||||
*
|
|
||||||
* @param string $field field name missing.
|
|
||||||
*/
|
|
||||||
public function __construct($field)
|
|
||||||
{
|
|
||||||
$this->field = $field;
|
|
||||||
$this->message = 'Configuration value is required for '. $this->field;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception used if an unauthorized attempt to edit configuration has been made.
|
|
||||||
*/
|
|
||||||
class UnauthorizedConfigException extends \Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Construct exception.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'You are not authorized to alter config.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
23
application/config/exception/MissingFieldConfigException.php
Normal file
23
application/config/exception/MissingFieldConfigException.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Shaarli\Config\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception used if a mandatory field is missing in given configuration.
|
||||||
|
*/
|
||||||
|
class MissingFieldConfigException extends \Exception
|
||||||
|
{
|
||||||
|
public $field;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct exception.
|
||||||
|
*
|
||||||
|
* @param string $field field name missing.
|
||||||
|
*/
|
||||||
|
public function __construct($field)
|
||||||
|
{
|
||||||
|
$this->field = $field;
|
||||||
|
$this->message = 'Configuration value is required for '. $this->field;
|
||||||
|
}
|
||||||
|
}
|
18
application/config/exception/UnauthorizedConfigException.php
Normal file
18
application/config/exception/UnauthorizedConfigException.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Shaarli\Config\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception used if an unauthorized attempt to edit configuration has been made.
|
||||||
|
*/
|
||||||
|
class UnauthorizedConfigException extends \Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Construct exception.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->message = 'You are not authorized to alter config.';
|
||||||
|
}
|
||||||
|
}
|
|
@ -106,7 +106,7 @@ public function testSetArrayKey()
|
||||||
/**
|
/**
|
||||||
* Try to write the config without mandatory parameter (e.g. 'login').
|
* Try to write the config without mandatory parameter (e.g. 'login').
|
||||||
*
|
*
|
||||||
* @expectedException Shaarli\Config\MissingFieldConfigException
|
* @expectedException Shaarli\Config\Exception\MissingFieldConfigException
|
||||||
*/
|
*/
|
||||||
public function testWriteMissingParameter()
|
public function testWriteMissingParameter()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue