mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-28 08:58:40 +00:00
Added custom exceptions
This commit is contained in:
parent
939253aa95
commit
33849c8a1f
|
|
@ -20,6 +20,7 @@ use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||||
use phpOMS\DataStorage\Database\DatabaseType;
|
use phpOMS\DataStorage\Database\DatabaseType;
|
||||||
use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar;
|
use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar;
|
||||||
use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGrammar;
|
use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGrammar;
|
||||||
|
use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database handler.
|
* Database handler.
|
||||||
|
|
@ -62,27 +63,27 @@ class MysqlConnection extends ConnectionAbstract
|
||||||
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
|
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
|
||||||
|
|
||||||
if(!isset($this->dbdata['db'])) {
|
if(!isset($this->dbdata['db'])) {
|
||||||
throw new \Exception('db');
|
throw new InvalidConnectionConfigException('db');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->dbdata['host'])) {
|
if(!isset($this->dbdata['host'])) {
|
||||||
throw new \Exception('host');
|
throw new InvalidConnectionConfigException('host');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->dbdata['port'])) {
|
if(!isset($this->dbdata['port'])) {
|
||||||
throw new \Exception('port');
|
throw new InvalidConnectionConfigException('port');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->dbdata['database'])) {
|
if(!isset($this->dbdata['database'])) {
|
||||||
throw new \Exception('database');
|
throw new InvalidConnectionConfigException('database');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->dbdata['login'])) {
|
if(!isset($this->dbdata['login'])) {
|
||||||
throw new \Exception('login');
|
throw new InvalidConnectionConfigException('login');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->dbdata['password'])) {
|
if(!isset($this->dbdata['password'])) {
|
||||||
throw new \Exception('password');
|
throw new InvalidConnectionConfigException('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->close();
|
$this->close();
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||||
use phpOMS\DataStorage\Database\Query\Builder;
|
use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
use phpOMS\DataStorage\DataMapperInterface;
|
use phpOMS\DataStorage\DataMapperInterface;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
use phpOMS\DataStorage\Database\Exception\InvalidMapperException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Datamapper for databases.
|
* Datamapper for databases.
|
||||||
|
|
@ -460,7 +461,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws InvalidMapperException
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -480,7 +481,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
||||||
throw new \Exception('No mapper set for relation object.');
|
throw new InvalidMapperException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var DataMapperAbstract $mapper */
|
/** @var DataMapperAbstract $mapper */
|
||||||
|
|
@ -679,7 +680,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws InvalidMapperException
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -699,7 +700,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
||||||
throw new \Exception('No mapper set for relation object.');
|
throw new InvalidMapperException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var DataMapperAbstract $mapper */
|
/** @var DataMapperAbstract $mapper */
|
||||||
|
|
@ -984,7 +985,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws InvalidMapperException
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -1004,7 +1005,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
||||||
throw new \Exception('No mapper set for relation object.');
|
throw new InvalidMapperException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var DataMapperAbstract $mapper */
|
/** @var DataMapperAbstract $mapper */
|
||||||
|
|
@ -1406,7 +1407,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \UnexpectedValueException
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.1
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @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 <dev@oms.com>
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
48
DataStorage/Database/Exception/InvalidMapperException.php
Normal file
48
DataStorage/Database/Exception/InvalidMapperException.php
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.1
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @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 <dev@oms.com>
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user