Issue #1938660 by fabpot: Fixed Remove the custom ExceptionListener class.

8.0.x
webchick 2013-03-10 12:09:19 -07:00
parent 37afef0004
commit c09959555f
3 changed files with 1 additions and 85 deletions

View File

@ -288,7 +288,7 @@ class CoreBundle extends Bundle {
$container->register('exception_controller', 'Drupal\Core\ExceptionController')
->addArgument(new Reference('content_negotiation'))
->addMethodCall('setContainer', array(new Reference('service_container')));
$container->register('exception_listener', 'Drupal\Core\EventSubscriber\ExceptionListener')
$container->register('exception_listener', 'Symfony\Component\HttpKernel\EventListener\ExceptionListener')
->addTag('event_subscriber')
->addArgument(array(new Reference('exception_controller'), 'execute'));

View File

@ -1,83 +0,0 @@
<?php
/*
* @file
* Definition of Drupal\Core\EventSubscriber\ExceptionListener.
*/
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Override of Symfony EventListener class to kill 403 and 404 from server logs.
*
* This is mostly a copy of Symfony's ExceptionListener but it doesn't have a
* $logger property as we are not currently using a logger. The class from
* Symfony will, in the absense of a logger, call error_log() on every http
* exception.
*
* @todo Remove this class once we introduce a logger.
*
* @see http://drupal.org/node/1803338
*/
class ExceptionListener implements EventSubscriberInterface {
private $controller;
public function __construct($controller) {
$this->controller = $controller;
}
public function onKernelException(GetResponseForExceptionEvent $event) {
static $handling;
if ($handling) {
return FALSE;
}
$handling = TRUE;
$exception = $event->getException();
$request = $event->getRequest();
// Do not put a line in the server logs for every HTTP error.
if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
}
$attributes = array(
'_controller' => $this->controller,
'exception' => FlattenException::create($exception),
'logger' => NULL,
'format' => $request->getRequestFormat(),
);
$request = $request->duplicate(NULL, NULL, $attributes);
$request->setMethod('GET');
try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, TRUE);
}
catch (\Exception $e) {
$message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage());
error_log($message);
// Set handling to false otherwise it won't be able to handle further
// exceptions.
$handling = FALSE;
return;
}
$event->setResponse($response);
$handling = FALSE;
}
public static function getSubscribedEvents() {
return array(
KernelEvents::EXCEPTION => array('onKernelException', -128),
);
}
}

View File

@ -13,7 +13,6 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Drupal\Core\EventSubscriber\ExceptionListener;
/**
* This controller handles HTTP errors generated by the routing system.