File io/db/dbms/Doctrine/Common/DoctrineException.php
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147:
<?php
/**
* var
* @package Doctrine
* @subpackage Common
* @license https://www.gnu.org/licenses/lgpl-2.1.fr.html LGPL 2.1
* @link https://www.doctrine-project.org
* @author Guilherme BLANCO <guilhermeblanco@hotmail.com>
* @author Jonathan WAGE <jonwage@gmail.com>
* @author Roman BORSCHEL <roman@code-factory.org>
* @version PHPBoost 5.2 - last update: 2014 12 22
* @since PHPBoost 4.0 - 2013 01 01
*/
function string_var_export($var) { return var_export($var, true); }
/**
* Base Exception class of Doctrine
* @package Doctrine
* @subpackage Common
* @license https://www.gnu.org/licenses/lgpl-2.1.fr.html LGPL 2.1
* @link https://www.doctrine-project.org
* @author Guilherme BLANCO <guilhermeblanco@hotmail.com>
* @author Jonathan WAGE <jonwage@gmail.com>
* @author Roman BORSCHEL <roman@code-factory.org>
* @version PHPBoost 5.2 - last update: 2016 11 14
* @since PHPBoost 4.0 - 2013 01 01
* @contributor mipel <mipel@phpboost.com>
*/
class DoctrineException extends Exception
{
/**
* @var array Lazy initialized array of error messages
* @static
*/
private static $_messages = array();
/**
* Initializes a new DoctrineException.
*
* @param string $message
* @param Exception $cause Optional Exception
*/
public function __construct($message = "", Exception $cause = null)
{
$code = ($cause instanceof Exception) ? $cause->getCode() : 0;
// parent::__construct($message, $code, $cause); // PHP 5.3
parent::__construct($message, $code);
}
/**
* Throws a DoctrineException reporting not implemented method in a given class
*
* @static
* @param string $method Method name
* @param string $class Class name
* @throws DoctrineException
*/
public static function notImplemented($method = null, $class = null)
{
if ($method && $class) {
return new self("The method '$method' is not implemented in class '$class'.");
} else if ($method && ! $class) {
return new self($method);
} else {
return new self('Functionality is not implemented.');
}
}
/**
* Implementation of __callStatic magic method.
*
* Received a method name and arguments. It lookups a $_messages HashMap
* for matching Class#Method key and executes the returned string value
* translating the placeholders with arguments passed.
*
* @static
* @param string $method Method name
* @param array $arguments Optional arguments to be translated in placeholders
* @throws DoctrineException
*/
public static function __callStatic($method, $arguments = array())
{
$class = get_called_class();
$messageKey = TextHelper::substr($class, TextHelper::strrpos($class, '\\') + 1) . "#$method";
$end = end($arguments);
$innerException = null;
if ($end instanceof Exception) {
$innerException = $end;
unset($arguments[count($arguments) - 1]);
}
if (($message = self::getExceptionMessage($messageKey)) !== false) {
$message = sprintf($message, $arguments);
} else {
$dumper = 'string_var_export';
$message = TextHelper::strtolower(preg_replace('~(?<=\\w)([A-Z])~u', '_$1', $method));
$message = TextHelper::ucfirst(str_replace('_', ' ', $message))
. ' (' . implode(', ', array_map($dumper, $arguments)) . ')';
}
return new $class($message, $innerException);
}
/**
* Retrieves error string given a message key for lookup
*
* @static
* @param string $messageKey
* @return string|false Returns the error string if found; FALSE otherwise
*/
public static function getExceptionMessage($messageKey)
{
if ( ! self::$_messages) {
// Lazy-init messages
self::$_messages = array(
'DoctrineException#partialObjectsAreDangerous' =>
"Loading partial objects is dangerous. Fetch full objects or consider " .
"using a different fetch mode. If you really want partial objects, " .
"set the doctrine.forcePartialLoad query hint to TRUE.",
'QueryException#nonUniqueResult' =>
"The query contains more than one result."
);
}
if (isset(self::$_messages[$messageKey])) {
return self::$_messages[$messageKey];
}
return false;
}
public static function unknownColumnType($type)
{
return new DoctrineException('Unknown column type "' . $type . '"');
}
public static function typeExists($type)
{
return new DoctrineException('Unknown column type "' . $type . '"');
}
}