Skip to content

Commit

Permalink
Create ExceptionHandlerInterface to allow third party exception handl…
Browse files Browse the repository at this point in the history
…ers' to handle fatal errors
  • Loading branch information
FineWolf committed Feb 28, 2014
1 parent 7baeaa2 commit 15d063b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -155,7 +155,7 @@ function ($row) {
$exceptionHandler = set_exception_handler('var_dump');
restore_exception_handler();

if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandlerInterface) {
if (self::$stackedErrorLevels) {
self::$stackedErrors[] = func_get_args();

Expand Down Expand Up @@ -263,7 +263,7 @@ public function handleFatal()
$exceptionHandler = set_exception_handler('var_dump');
restore_exception_handler();

if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandlerInterface) {
$this->handleFatalError($exceptionHandler[0], $error);
}
}
Expand All @@ -284,7 +284,7 @@ protected function getFatalErrorHandlers()
);
}

private function handleFatalError(ExceptionHandler $exceptionHandler, array $error)
private function handleFatalError(ExceptionHandlerInterface $exceptionHandler, array $error)
{
$level = isset($this->levels[$error['type']]) ? $this->levels[$error['type']] : $error['type'];
$message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']);
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Debug/ExceptionHandler.php
Expand Up @@ -29,7 +29,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ExceptionHandler
class ExceptionHandler implements ExceptionHandlerInterface
{
private $debug;
private $charset;
Expand Down Expand Up @@ -57,14 +57,14 @@ public static function register($debug = true)
}

/**
* {@inheritDoc}
*
* Sends a response for the given Exception.
*
* If you have the Symfony HttpFoundation component installed,
* this method will use it to create and send the response. If not,
* it will fallback to plain PHP functions.
*
* @param \Exception $exception An \Exception instance
*
* @see sendPhpResponse
* @see createResponse
*/
Expand Down
27 changes: 27 additions & 0 deletions src/Symfony/Component/Debug/ExceptionHandlerInterface.php
@@ -0,0 +1,27 @@
<?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;

/**
* An ExceptionHandler does something useful with an exception.
*
* @author Andrew Moore <me@andrewmoore.ca>
*/
interface ExceptionHandlerInterface
{
/**
* Handles an exception.
*
* @param \Exception $exception An \Exception instance
*/
public function handle(\Exception $exception);
}

0 comments on commit 15d063b

Please sign in to comment.