Skip to content

Commit

Permalink
ErrorHandler and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 authored and fabpot committed Jun 2, 2013
1 parent b5c9bb8 commit 3db0360
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Debug;

use Symfony\Component\Debug\Exception\FatalErrorException;
use Symfony\Component\Debug\Exception\ContextErrorException;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions src/Symfony/Component/Debug/Exception/ContextErrorException.php
@@ -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;
}
}

0 comments on commit 3db0360

Please sign in to comment.