diff --git a/core/core.services.yml b/core/core.services.yml index 06d2b17..00fa864 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -6,9 +6,7 @@ services: - [setContainer, ['@service_container']] cache_contexts: class: Drupal\Core\Cache\CacheContexts - arguments: ['%cache_contexts%' ] - calls: - - [setContainer, ['@service_container']] + arguments: ['@service_container', '%cache_contexts%' ] cache_context.url: class: Drupal\Core\Cache\UrlCacheContext arguments: ['@request'] @@ -117,17 +115,13 @@ services: - [setRequest, ['@?request=']] keyvalue: class: Drupal\Core\KeyValueStore\KeyValueFactory - arguments: ['@settings'] - calls: - - [setContainer, ['@service_container']] + arguments: ['@service_container', '@settings'] keyvalue.database: class: Drupal\Core\KeyValueStore\KeyValueDatabaseFactory arguments: ['@database'] keyvalue.expirable: class: Drupal\Core\KeyValueStore\KeyValueExpirableFactory - arguments: ['@settings'] - calls: - - [setContainer, ['@service_container']] + arguments: ['@service_container', '@settings'] keyvalue.expirable.database: class: Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory tags: diff --git a/core/lib/Drupal/Core/Cache/CacheContexts.php b/core/lib/Drupal/Core/Cache/CacheContexts.php index 040c2f3..cbc2e9e 100644 --- a/core/lib/Drupal/Core/Cache/CacheContexts.php +++ b/core/lib/Drupal/Core/Cache/CacheContexts.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Cache; use Drupal\Core\Database\Query\SelectInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines the CacheContexts service. @@ -17,7 +17,14 @@ * cache key. */ class CacheContexts { - use ContainerAwareTrait; + + /** + * The service container. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + /** * Available cache contexts and corresponding labels. * @@ -28,12 +35,15 @@ class CacheContexts { /** * Constructs a CacheContexts object. * + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The current service container. * @param array $contexts * An array of key-value pairs, where the keys are service names (which also * serve as the corresponding cache context token) and the values are the * cache context labels. */ - public function __construct(array $contexts) { + public function __construct(ContainerInterface $container, array $contexts) { + $this->container = $container; $this->contexts = $contexts; } diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php index ae40d43..b1efbf0 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php @@ -7,6 +7,8 @@ namespace Drupal\Core\KeyValueStore; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Defines the key/value store factory. */ diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php index 0d68119..a1a9d65 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php @@ -7,13 +7,13 @@ namespace Drupal\Core\KeyValueStore; use Drupal\Component\Utility\Settings; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines the key/value store factory. */ class KeyValueFactory implements KeyValueFactoryInterface { - use ContainerAwareTrait; + /** * The specific setting name prefix. * @@ -45,6 +45,11 @@ class KeyValueFactory implements KeyValueFactoryInterface { protected $stores = array(); /** + * var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** * The read-only settings container. * * @var \Drupal\Component\Utility\Settings @@ -52,10 +57,13 @@ class KeyValueFactory implements KeyValueFactoryInterface { protected $settings; /** + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The service container. * @param \Drupal\Component\Utility\Settings $settings * The read-only settings container. */ - function __construct( Settings $settings) { + function __construct(ContainerInterface $container, Settings $settings) { + $this->container = $container; $this->settings = $settings; } diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php index aaf8bbc..4b48cfb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php @@ -57,11 +57,11 @@ protected function setUp() { ->setFactoryMethod('getInstance'); $this->container ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory') - ->addMethodCall('setContainer', array(new Reference('service_container'))) + ->addArgument(new Reference('service_container')) ->addArgument(new Reference('settings')); $this->container ->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueExpirableFactory') - ->addMethodCall('setContainer', array(new Reference('service_container'))) + ->addArgument(new Reference('service_container')) ->addArgument(new Reference('settings')); // Define two data collections, $this->collections = array(0 => 'zero', 1 => 'one'); diff --git a/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php b/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php index 6437707..7c8be0b 100644 --- a/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php +++ b/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/EventSubscriber/ThemeTestSubscriber.php @@ -7,7 +7,6 @@ namespace Drupal\theme_test\EventSubscriber; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -16,9 +15,20 @@ * Theme test subscriber for controller requests. */ class ThemeTestSubscriber implements EventSubscriberInterface { - use ContainerAwareTrait; /** + * The used container. + * + * @var \Symfony\Component\DependencyInjection\IntrospectableContainerInterface + */ + protected $container; + + public function __construct() { + // @todo - Must initialize $container. + // see onView() + } + + /** * Generates themed output early in a page request. * * @see \Drupal\system\Tests\Theme\ThemeEarlyInitializationTest::testRequestListener() diff --git a/core/modules/system/tests/modules/theme_test/theme_test.services.yml b/core/modules/system/tests/modules/theme_test/theme_test.services.yml index 69fd3ca..d0ada2b 100644 --- a/core/modules/system/tests/modules/theme_test/theme_test.services.yml +++ b/core/modules/system/tests/modules/theme_test/theme_test.services.yml @@ -1,6 +1,8 @@ services: theme_test.subscriber: class: Drupal\theme_test\EventSubscriber\ThemeTestSubscriber + calls: + - [setContainer, ['@service_container']] tags: - { name: event_subscriber } diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php index be5add1..6e5864d 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php @@ -55,8 +55,7 @@ public function testContextPlaceholdersAreReplaced() { ->with("cache_context.foo") ->will($this->returnValue(new FooCacheContext())); - $cache_contexts = new CacheContexts($this->getContextsFixture()); - $cache_contexts->setContainer($container); + $cache_contexts = new CacheContexts($container, $this->getContextsFixture()); $new_keys = $cache_contexts->convertTokensToKeys( array("non-cache-context", "cache_context.foo") @@ -67,8 +66,7 @@ public function testContextPlaceholdersAreReplaced() { } public function testAvailableContextStrings() { - $cache_contexts = new CacheContexts($this->getContextsFixture()); - $cache_contexts->setContainer($this->getMockContainer()); + $cache_contexts = new CacheContexts($this->getMockContainer(), $this->getContextsFixture()); $contexts = $cache_contexts->getAll(); $this->assertEquals(array("cache_context.foo"), $contexts); } @@ -80,8 +78,7 @@ public function testAvailableContextLabels() { ->with("cache_context.foo") ->will($this->returnValue(new FooCacheContext())); - $cache_contexts = new CacheContexts($this->getContextsFixture()); - $cache_contexts->setContainer($this->getMockContainer()); + $cache_contexts = new CacheContexts($container, $this->getContextsFixture()); $labels = $cache_contexts->getLabels(); $expected = array("cache_context.foo" => "Foo"); $this->assertEquals($expected, $labels);