Commit 31909ee8 authored by catch's avatar catch
Browse files

Issue #1777430 by Crell, sun: Fixed Allow for ContainerAware controllers.

parent 71b5ccf9
<?php
/**
* @file
* Definition of Drupal\Core\ControllerResolver.
*/
namespace Drupal\Core;
use Symfony\Component\HttpKernel\Controller\ControllerResolver as BaseControllerResolver;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* ControllerResolver to enhance controllers beyond Symfony's basic handling.
*
* When creating a new object-based controller that implements
* ContainerAwareInterface, inject the container into it. While not always
* necessary, that allows a controller to vary the services it needs at runtime.
*/
class ControllerResolver extends BaseControllerResolver {
/**
* The injection container that should be injected into all controllers.
*
* @var Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* Constructs a new ControllerResolver.
*
* @param Symfony\Component\DependencyInjection\ContainerInterface $container
* A ContainerInterface instance.
* @param Symfony\Component\HttpKernel\Log\LoggerInterface $logger
* (optional) A LoggerInterface instance.
*/
public function __construct(ContainerInterface $container, LoggerInterface $logger = NULL) {
$this->container = $container;
parent::__construct($logger);
}
/**
* Returns a callable for the given controller.
*
* @param string $controller
* A Controller string.
*
* @return mixed
* A PHP callable.
*/
protected function createController($controller) {
$controller = parent::createController($controller);
// $controller will be an array of object and method name, per PHP's
// definition of a callable. Index 0 therefore is the object we want to
// enhance.
if ($controller[0] instanceof ContainerAwareInterface) {
$controller[0]->setContainer($this->container);
}
}
}
......@@ -35,7 +35,8 @@ public function build(ContainerBuilder $container) {
$container->register('dispatcher', 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher')
->addArgument(new Reference('service_container'));
$container->register('resolver', 'Symfony\Component\HttpKernel\Controller\ControllerResolver');
$container->register('resolver', 'Drupal\Core\ControllerResolver')
->addArgument(new Reference('service_container'));
$container->register('http_kernel', 'Drupal\Core\HttpKernel')
->addArgument(new Reference('dispatcher'))
->addArgument(new Reference('service_container'))
......@@ -69,6 +70,7 @@ public function build(ContainerBuilder $container) {
$dispatcher->addSubscriber(new \Drupal\Core\EventSubscriber\ConfigGlobalOverrideSubscriber());
$container->set('content_negotiation', $content_negotation);
$dispatcher->addSubscriber(\Drupal\Core\ExceptionController::getExceptionListener($container));
/*
$container->register('matcher', 'Drupal\Core\LegacyUrlMatcher');
$container->register('router_listener', 'Drupal\Core\EventSubscriber\RouterListener')
......
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