2008-09-12 17:08:01 +04:00
|
|
|
<?php
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Common;
|
|
|
|
|
|
|
|
class DoctrineException extends \Exception
|
2008-09-12 17:08:01 +04:00
|
|
|
{
|
|
|
|
private $_innerException;
|
2009-02-19 10:00:54 +03:00
|
|
|
private static $_messages = array();
|
|
|
|
|
2008-09-12 17:08:01 +04:00
|
|
|
public function __construct($message = "", Exception $innerException = null)
|
|
|
|
{
|
|
|
|
parent::__construct($message);
|
|
|
|
$this->_innerException = $innerException;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInnerException()
|
|
|
|
{
|
|
|
|
return $this->_innerException;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function notImplemented($method, $class)
|
|
|
|
{
|
2008-12-18 17:08:11 +03:00
|
|
|
return new self("The method '$method' is not implemented in class '$class'.");
|
2008-09-12 17:08:01 +04:00
|
|
|
}
|
|
|
|
|
2009-02-19 10:00:54 +03:00
|
|
|
public static function __callStatic($method, $arguments)
|
|
|
|
{
|
|
|
|
$end = end($arguments);
|
|
|
|
if ($end instanceof Exception) {
|
|
|
|
$this->_innerException = $end;
|
|
|
|
unset($arguments[count($arguments) - 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset(self::$_messages[$method])) {
|
|
|
|
$message = sprintf(self::$_messages[$method], $arguments);
|
|
|
|
} else {
|
|
|
|
$message = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $method));
|
|
|
|
$message = ucfirst(str_replace('_', ' ', $message));
|
|
|
|
$args = array();
|
|
|
|
foreach ($arguments as $argument) {
|
|
|
|
$args[] = var_export($argument, true);
|
|
|
|
}
|
|
|
|
$message .= ' (' . implode(', ', $args) . ')';
|
|
|
|
}
|
|
|
|
return new self($message);
|
|
|
|
}
|
|
|
|
}
|