phpOMS/DataStorage/Database/DatabaseExceptionFactory.php

67 lines
1.4 KiB
PHP

<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database;
use phpOMS\DataStorage\Database\Schema\Exception\TableException;
/**
* Database exception factory.
*
* @package Framework
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class DatabaseExceptionFactory
{
/**
* Constructor.
*
* @param \PDOException $e Exception
*
* @return string
*
* @since 1.0.0
*/
public static function createException(\PDOException $e) : string
{
switch ($e->getCode()) {
case '42S02':
return '\phpOMS\DataStorage\Database\Schema\Exception\TableException';
default:
return '\PDOException';
}
}
/**
* Constructor.
*
* @param \PDOException $e Exception
*
* @return string
*
* @since 1.0.0
*/
public static function createExceptionMessage(\PDOException $e) : string
{
switch ($e->getCode()) {
case '42S02':
return TableException::findTable($e->getMessage());
default:
return $e->getMessage();
}
}
}