Commit 1d1c62b2 authored by katbailey's avatar katbailey

Using a factory method to get an ExceptionListener as it needs to be passed an...

Using a factory method to get an ExceptionListener as it needs to be passed an instantiated ExceptionController
parent ea2d59c6
......@@ -53,14 +53,18 @@ public function build(ContainerBuilder $container)
$definition->addMethodCall($method, $args);
}
if (isset($info['container_aware'])) {
$definition->addMethodCall('setContainer', array(new Reference('service_container')));
}
$container->setDefinition($id, $definition);
}
$container->register('exception_listener', 'Symfony\Component\HttpKernel\EventListener\ExceptionListener')
->addTag('kernel.event_subscriber')
->addArgument(new Reference('service_container'))
->setFactoryClass('Drupal\Core\ExceptionController')
->setFactoryMethod('getExceptionListener');
// Add a compiler pass for registering event subscribers.
$container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
}
/**
......@@ -127,16 +131,6 @@ function getDefinitions() {
'class' => 'Drupal\Core\EventSubscriber\RequestCloseSubscriber',
'tags' => array('kernel.event_subscriber')
),
'exception_controller' => array(
'class' => 'Drupal\Core\ExceptionController',
'references' => array('content_negotiation'),
'container_aware' => TRUE,
),
'exception_listener' => array(
'class' => 'Symfony\Component\HttpKernel\EventListener\ExceptionListener',
'references' => array('exception_controller'),
'tags' => array('kernel.event_subscriber')
),
'database' => array(
'class' => 'Drupal\Core\Database\Connection',
'factory_class' => 'Drupal\Core\Database\Database',
......
......@@ -7,12 +7,14 @@
namespace Drupal\Core;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
/**
* This controller handles HTTP errors generated by the routing system.
......@@ -26,6 +28,13 @@ class ExceptionController extends ContainerAware {
*/
protected $negotiation;
public static function getExceptionListener(Container $container) {
$negotiation = $container->get('content_negotiation');
$exceptionController = new self($negotiation);
$exceptionController->setContainer($container);
return new ExceptionListener(array($exceptionController, 'execute'));
}
/**
* Constructor.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment