diff --git a/DataStorage/Database/Connection/MysqlConnection.php b/DataStorage/Database/Connection/MysqlConnection.php index af4c2ed02..719031e69 100644 --- a/DataStorage/Database/Connection/MysqlConnection.php +++ b/DataStorage/Database/Connection/MysqlConnection.php @@ -20,6 +20,7 @@ use phpOMS\DataStorage\Database\DatabaseStatus; use phpOMS\DataStorage\Database\DatabaseType; use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar; use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGrammar; +use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException; /** * Database handler. @@ -62,27 +63,27 @@ class MysqlConnection extends ConnectionAbstract $this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata; if(!isset($this->dbdata['db'])) { - throw new \Exception('db'); + throw new InvalidConnectionConfigException('db'); } if(!isset($this->dbdata['host'])) { - throw new \Exception('host'); + throw new InvalidConnectionConfigException('host'); } if(!isset($this->dbdata['port'])) { - throw new \Exception('port'); + throw new InvalidConnectionConfigException('port'); } if(!isset($this->dbdata['database'])) { - throw new \Exception('database'); + throw new InvalidConnectionConfigException('database'); } if(!isset($this->dbdata['login'])) { - throw new \Exception('login'); + throw new InvalidConnectionConfigException('login'); } if(!isset($this->dbdata['password'])) { - throw new \Exception('password'); + throw new InvalidConnectionConfigException('password'); } $this->close(); diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 7552b6324..7165af099 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -20,6 +20,7 @@ use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\DataMapperInterface; use phpOMS\Message\RequestAbstract; +use phpOMS\DataStorage\Database\Exception\InvalidMapperException; /** * Datamapper for databases. @@ -460,7 +461,7 @@ class DataMapperAbstract implements DataMapperInterface * * @return void * - * @throws \Exception + * @throws InvalidMapperException * * @since 1.0.0 */ @@ -480,7 +481,7 @@ class DataMapperAbstract implements DataMapperInterface } if (!isset(static::$hasMany[$propertyName]['mapper'])) { - throw new \Exception('No mapper set for relation object.'); + throw new InvalidMapperException(); } /** @var DataMapperAbstract $mapper */ @@ -679,7 +680,7 @@ class DataMapperAbstract implements DataMapperInterface * * @return void * - * @throws \Exception + * @throws InvalidMapperException * * @since 1.0.0 */ @@ -699,7 +700,7 @@ class DataMapperAbstract implements DataMapperInterface } if (!isset(static::$hasMany[$propertyName]['mapper'])) { - throw new \Exception('No mapper set for relation object.'); + throw new InvalidMapperException(); } /** @var DataMapperAbstract $mapper */ @@ -984,7 +985,7 @@ class DataMapperAbstract implements DataMapperInterface * * @return void * - * @throws \Exception + * @throws InvalidMapperException * * @since 1.0.0 */ @@ -1004,7 +1005,7 @@ class DataMapperAbstract implements DataMapperInterface } if (!isset(static::$hasMany[$propertyName]['mapper'])) { - throw new \Exception('No mapper set for relation object.'); + throw new InvalidMapperException(); } /** @var DataMapperAbstract $mapper */ @@ -1406,7 +1407,7 @@ class DataMapperAbstract implements DataMapperInterface * * @return mixed * - * @throws \Exception + * @throws \UnexpectedValueException * * @since 1.0.0 */ diff --git a/DataStorage/Database/Exception/InvalidConnectionConfigException.php b/DataStorage/Database/Exception/InvalidConnectionConfigException.php new file mode 100644 index 000000000..f3fec1deb --- /dev/null +++ b/DataStorage/Database/Exception/InvalidConnectionConfigException.php @@ -0,0 +1,44 @@ + + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); + +namespace phpOMS\DataStorage\Database\Exception; + +/** + * Permission exception class. + * + * @category Framework + * @package phpOMS\System\File + * @author OMS Development Team + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class InvalidConnectionConfigException extends \RuntimeException +{ + /** + * Constructor. + * + * @param string $message Exception message + * @param int $code Exception code + * @param \Exception Previous exception + * + * @since 1.0.0 + */ + public function __construct(string $message = '', int $code = 0, \Exception $previous = null) + { + parent::__construct('Missing config value for "'. $message .'".', $code, $previous); + } +} diff --git a/DataStorage/Database/Exception/InvalidMapperException.php b/DataStorage/Database/Exception/InvalidMapperException.php new file mode 100644 index 000000000..4e914f79d --- /dev/null +++ b/DataStorage/Database/Exception/InvalidMapperException.php @@ -0,0 +1,48 @@ + + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); + +namespace phpOMS\DataStorage\Database\Exception; + +/** + * Permission exception class. + * + * @category Framework + * @package phpOMS\System\File + * @author OMS Development Team + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class InvalidMapperException extends \RuntimeException +{ + /** + * Constructor. + * + * @param string $message Exception message + * @param int $code Exception code + * @param \Exception Previous exception + * + * @since 1.0.0 + */ + public function __construct(string $message = '', int $code = 0, \Exception $previous = null) + { + if($message === '') { + parent::__construct('Empty mapper.', $code, $previous); + } else { + parent::__construct('Mapper "' . $message . '" is invalid.', $code, $previous); + } + } +}