From: Martin Hason Date: Mon, 10 Jan 2011 15:03:48 +0000 (+0100) Subject: make Twig_Error compatible with PHP 5.3.0 > X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=8adcbd971df62a0bf98d1ed1c850f5d15a8c7934;p=web%2Fkonrad%2Ftwig.git make Twig_Error compatible with PHP 5.3.0 > --- diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index e59785e..6604384 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -20,15 +20,17 @@ class Twig_Error extends Exception protected $lineno; protected $filename; protected $rawMessage; + protected $previous; /** * Constructor. * - * @param string $message The error message - * @param integer $lineno The template line where the error occurred - * @param string $filename The template file name where the error occurred + * @param string $message The error message + * @param integer $lineno The template line where the error occurred + * @param string $filename The template file name where the error occurred + * @param Exception $previous The previous exception */ - public function __construct($message, $lineno = -1, $filename = null) + public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null) { $this->lineno = $lineno; $this->filename = $filename; @@ -36,7 +38,12 @@ class Twig_Error extends Exception $this->updateRepr(); - parent::__construct($this->message); + if (version_compare(PHP_VERSION, '5.3.0', '<')) { + $this->previous = $previous; + parent::__construct($this->message); + } else { + parent::__construct($this->message, 0, $previous); + } } /** @@ -83,6 +90,22 @@ class Twig_Error extends Exception $this->updateRepr(); } + /** + * For PHP < 5.3.0, provides access to the getPrevious() method. + * + * @param string $method The method name + * @param array $args The parameters to be passed to the method + * + * @return Exception The previous exception or null + */ + public function __call($method, array $args) + { + if ('getprevious' == strtolower($method)) { + return $this->previous; + } + return null; + } + protected function updateRepr() { $this->message = $this->rawMessage;