From 3db0360bd928bb6dcca57dc1ec8748441e4685ac Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Fri, 31 May 2013 14:57:00 +0200 Subject: [PATCH] ErrorHandler and fixes --- src/Symfony/Component/Debug/ErrorHandler.php | 7 ++-- .../Debug/Exception/ContextErrorException.php | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Component/Debug/Exception/ContextErrorException.php diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 549588ffd0a4..07ee7c1b6c97 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Debug; use Symfony\Component\Debug\Exception\FatalErrorException; +use Symfony\Component\Debug\Exception\ContextErrorException; use Psr\Log\LoggerInterface; /** @@ -89,9 +90,9 @@ public static function setLogger(LoggerInterface $logger, $channel = 'deprecatio } /** - * @throws \ErrorException When error_reporting returns error + * @throws ContextErrorException When error_reporting returns error */ - public function handle($level, $message, $file, $line, $context) + public function handle($level, $message, $file = 'unknown', $line = 0, $context = array()) { if (0 === $this->level) { return false; @@ -118,7 +119,7 @@ function ($row) { } if ($this->displayErrors && error_reporting() & $level && $this->level & $level) { - throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line); + throw new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context); } return false; diff --git a/src/Symfony/Component/Debug/Exception/ContextErrorException.php b/src/Symfony/Component/Debug/Exception/ContextErrorException.php new file mode 100644 index 000000000000..2e0115f0cfec --- /dev/null +++ b/src/Symfony/Component/Debug/Exception/ContextErrorException.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Debug\Exception; + +/** + * Error Exception with Variable Context. + * + * @author Christian Sciberras + */ +class ContextErrorException extends \ErrorException +{ + private $context = array(); + + public function __construct($message, $code, $severity, $filename, $lineno, $context = array()) + { + parent::__construct($message, $code, $severity, $filename, $lineno); + $this->context = $context; + } + + /** + * @return array Array of variables that existed when the exception occured + */ + public function getContext() + { + return $this->context; + } +}