Commit 12b53d00 authored by alexpott's avatar alexpott

Issue #2229183 by martin107, dawehner: Use ContainerAwareTrait instead of extending ContainerAware.

parent 8894e438
......@@ -183,6 +183,10 @@ services:
arguments: [ '%container.namespaces%' ]
tags:
- { name: persist }
container.trait:
abstract: true
calls:
- [setContainer, ['@service_container']]
default_plugin_manager:
abstract: true
arguments: ['@container.namespaces', '@cache.discovery', '@language_manager', '@module_handler']
......@@ -194,7 +198,8 @@ services:
arguments: ['@config.factory', '@module_handler', '@cache.default', '@info_parser', '@config.installer', '@router.builder']
entity.manager:
class: Drupal\Core\Entity\EntityManager
arguments: ['@container.namespaces', '@service_container', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation']
arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation']
parent: container.trait
tags:
- { name: plugin_manager_cache_clear }
entity.form_builder:
......@@ -239,13 +244,14 @@ services:
arguments: ['@service_container']
controller_resolver:
class: Drupal\Core\Controller\ControllerResolver
arguments: ['@service_container']
parent: container.trait
title_resolver:
class: Drupal\Core\Controller\TitleResolver
arguments: ['@controller_resolver', '@string_translation']
http_kernel:
class: Drupal\Core\HttpKernel
arguments: ['@event_dispatcher', '@service_container', '@controller_resolver', '@request_stack']
arguments: ['@event_dispatcher', '@controller_resolver', '@request_stack']
parent: container.trait
language_manager:
class: Drupal\Core\Language\LanguageManager
arguments: ['@language.default']
......@@ -431,7 +437,8 @@ services:
- { name: event_subscriber }
route_content_form_controller_subscriber:
class: Drupal\Core\EventSubscriber\ContentFormControllerSubscriber
arguments: ['@service_container', '@controller_resolver', '@form_builder']
arguments: ['@controller_resolver', '@form_builder']
parent: container.trait
tags:
- { name: event_subscriber }
route_special_attributes_subscriber:
......
......@@ -16,7 +16,8 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
......@@ -26,7 +27,9 @@
*
* @see \Drupal\Tests\Core\Access\AccessManagerTest
*/
class AccessManager extends ContainerAware {
class AccessManager implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* Array of registered access check service ids.
......
......@@ -11,10 +11,13 @@
* Defines the cache backend factory.
*/
use Drupal\Component\Utility\Settings;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class CacheFactory extends ContainerAware implements CacheFactoryInterface {
class CacheFactory implements CacheFactoryInterface, ContainerAwareInterface {
use ContainerAwareTrait;
/**
* The settings array.
......
......@@ -8,13 +8,16 @@
namespace Drupal\Core\Controller;
use Drupal\Core\Ajax\AjaxResponseRenderer;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
/**
* Default controller for Ajax requests.
*/
class AjaxController extends ContainerAware {
class AjaxController implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* The controller resolver.
......
......@@ -11,7 +11,7 @@
use Symfony\Component\HttpKernel\Controller\ControllerResolver as BaseControllerResolver;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* ControllerResolver to enhance controllers beyond Symfony's basic handling.
......@@ -28,14 +28,9 @@
* controller by using a service:method notation (Symfony uses the same
* convention).
*/
class ControllerResolver extends BaseControllerResolver implements ControllerResolverInterface {
class ControllerResolver extends BaseControllerResolver implements ControllerResolverInterface, ContainerAwareInterface {
/**
* The injection container that should be injected into all controllers.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
use ContainerAwareTrait;
/**
* The PSR-3 logger. (optional)
......@@ -47,14 +42,10 @@ class ControllerResolver extends BaseControllerResolver implements ControllerRes
/**
* 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;
public function __construct(LoggerInterface $logger = NULL) {
parent::__construct($logger);
}
......
......@@ -24,7 +24,8 @@
use Drupal\Core\Plugin\Discovery\InfoHookDecorator;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* Manages entity type plugin definitions.
......@@ -40,7 +41,9 @@
* @see \Drupal\Core\Entity\EntityTypeInterface
* @see hook_entity_type_alter()
*/
class EntityManager extends PluginManagerBase implements EntityManagerInterface {
class EntityManager extends PluginManagerBase implements EntityManagerInterface, ContainerAwareInterface {
use ContainerAwareTrait;
/**
* Extra fields by bundle.
......@@ -49,13 +52,6 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
*/
protected $extraFields = array();
/**
* The injection container that should be passed into the controller factory.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* Contains instantiated controllers keyed by controller type and entity type.
*
......@@ -144,8 +140,6 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container this object should use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
......@@ -155,7 +149,7 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager
* The string translationManager.
*/
public function __construct(\Traversable $namespaces, ContainerInterface $container, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, TranslationInterface $translation_manager) {
public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, TranslationInterface $translation_manager) {
// Allow the plugin definition to be altered by hook_entity_type_alter().
$this->moduleHandler = $module_handler;
......@@ -169,7 +163,6 @@ public function __construct(\Traversable $namespaces, ContainerInterface $contai
$this->discovery = new AlterDecorator($this->discovery, 'entity_type');
$this->discovery = new CacheDecorator($this->discovery, 'entity_type:' . $this->languageManager->getCurrentLanguage()->id, 'discovery', Cache::PERMANENT, array('entity_types' => TRUE));
$this->container = $container;
}
/**
......
......@@ -8,12 +8,15 @@
namespace Drupal\Core\Entity\Query;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* Factory class Creating entity query objects.
*/
class QueryFactory extends ContainerAware {
class QueryFactory implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* Stores the entity manager used by the query.
......
......@@ -13,19 +13,15 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* Subscriber for setting wrapping form logic.
*/
class ContentFormControllerSubscriber implements EventSubscriberInterface {
class ContentFormControllerSubscriber implements EventSubscriberInterface, ContainerAwareInterface {
/**
* The service container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
use ContainerAwareTrait;
/**
* The controller resolver.
......@@ -44,15 +40,12 @@ class ContentFormControllerSubscriber implements EventSubscriberInterface {
/**
* Constructs a new ContentFormControllerSubscriber object.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container.
* @param \Drupal\Core\Controller\ControllerResolverInterface $resolver
* The controller resolver.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
*/
public function __construct(ContainerInterface $container, ControllerResolverInterface $resolver, FormBuilderInterface $form_builder) {
$this->container = $container;
public function __construct(ControllerResolverInterface $resolver, FormBuilderInterface $form_builder) {
$this->resolver = $resolver;
$this->formBuilder = $form_builder;
}
......
......@@ -6,8 +6,8 @@
*/
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
......@@ -15,8 +15,9 @@
/**
* Destructs services that are initiated and tagged with "needs_destruction".
*/
class KernelDestructionSubscriber extends ContainerAware implements EventSubscriberInterface {
class KernelDestructionSubscriber implements EventSubscriberInterface, ContainerAwareInterface {
use ContainerAwareTrait;
/**
* Holds an array of service ID's that will require destruction.
*
......
......@@ -14,14 +14,12 @@
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\HttpKernel as BaseHttpKernel;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* This HttpKernel is used to manage scope changes of the DI container.
......@@ -29,30 +27,11 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class HttpKernel extends BaseHttpKernel
{
protected $container;
class HttpKernel extends BaseHttpKernel implements ContainerAwareInterface {
private $esiSupport;
/**
* Constructs a new HttpKernel.
*
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The event dispatcher.
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The dependency injection container.
* @param \Symfony\Component\HttpKernel\Controller\ControllerResolverInterface $controller_resolver
* The controller resolver.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
*/
public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controller_resolver, RequestStack $request_stack = NULL)
{
parent::__construct($dispatcher, $controller_resolver, $request_stack);
use ContainerAwareTrait;
$this->container = $container;
}
private $esiSupport;
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
......
......@@ -7,7 +7,8 @@
namespace Drupal\Core\ParamConverter;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\HttpFoundation\Request;
......@@ -18,7 +19,9 @@
* A typical use case for this would be upcasting (converting) a node id to a
* node entity.
*/
class ParamConverterManager extends ContainerAware implements ParamConverterManagerInterface {
class ParamConverterManager implements ParamConverterManagerInterface, ContainerAwareInterface {
use ContainerAwareTrait;
/**
* An array of registered converter service ids.
......
......@@ -8,12 +8,15 @@
namespace Drupal\Core\Queue;
use Drupal\Component\Utility\Settings;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* Defines the queue factory.
*/
class QueueFactory extends ContainerAware {
class QueueFactory implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* Instantiated queues, keyed by name.
......
......@@ -7,7 +7,8 @@
namespace Drupal\contextual;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
......@@ -16,7 +17,9 @@
/**
* Returns responses for Contextual module routes.
*/
class ContextualController extends ContainerAware {
class ContextualController implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* Returns the requested rendered contextual links.
......
......@@ -8,7 +8,8 @@
namespace Drupal\rest;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
......@@ -18,7 +19,9 @@
/**
* Acts as intermediate request forwarder for resource plugins.
*/
class RequestHandler extends ContainerAware {
class RequestHandler implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* Handles a web API request.
......
......@@ -13,7 +13,6 @@
use Drupal\Core\Language\Language;
use Symfony\Component\DependencyInjection\Reference;
use Drupal\Core\Database\Database;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
......
......@@ -7,7 +7,6 @@
namespace Drupal\theme_test\EventSubscriber;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -15,7 +14,7 @@
/**
* Theme test subscriber for controller requests.
*/
class ThemeTestSubscriber extends ContainerAware implements EventSubscriberInterface {
class ThemeTestSubscriber implements EventSubscriberInterface {
/**
* The used container.
......@@ -24,6 +23,7 @@ class ThemeTestSubscriber extends ContainerAware implements EventSubscriberInter
*/
protected $container;
/**
* Generates themed output early in a page request.
*
......
......@@ -59,7 +59,8 @@ protected function setUp() {
parent::setUp();
$this->container = new ContainerBuilder();
$this->controllerResolver = new ControllerResolver($this->container);
$this->controllerResolver = new ControllerResolver();
$this->controllerResolver->setContainer($this->container);
}
/**
......
......@@ -149,7 +149,8 @@ protected function setUpEntityManager($definitions = array()) {
->method('getDefinitions')
->will($this->returnValue($definitions));
$this->entityManager = new TestEntityManager(new \ArrayObject(), $this->container, $this->moduleHandler, $this->cache, $this->languageManager, $this->translationManager, $this->formBuilder);
$this->entityManager = new TestEntityManager(new \ArrayObject(), $this->moduleHandler, $this->cache, $this->languageManager, $this->translationManager, $this->formBuilder);
$this->entityManager->setContainer($this->container);
$this->entityManager->setDiscovery($this->discovery);
}
......
......@@ -46,9 +46,11 @@ public function testSetupSubrequest() {
$container->set('request', $request, 'request');
$dispatcher = new EventDispatcher();
$controller_resolver = new ControllerResolver($container);
$controller_resolver = new ControllerResolver();
$controller_resolver->setContainer($container);
$http_kernel = new HttpKernel($dispatcher, $container, $controller_resolver);
$http_kernel = new HttpKernel($dispatcher, $controller_resolver);
$http_kernel->setContainer($container);
$test_controller = '\Drupal\Tests\Core\Controller\TestController';
$random_attribute = $this->randomName();
......
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