ErrorHandler and fixes

This commit is contained in:
Christian Sciberras 2013-05-31 14:57:00 +02:00 committed by Fabien Potencier
parent b5c9bb8e03
commit 3db0360bd9
2 changed files with 40 additions and 3 deletions

View File

@ -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 @@ class ErrorHandler
}
/**
* @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 @@ class ErrorHandler
}
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;

View File

@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <uuf6429@gmail.com>
*/
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;
}
}