summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-06-28 16:11:57 (GMT)
committerAlex Pott2013-06-28 16:13:22 (GMT)
commitb1c684b8f82e103764422acd95cab332dd7904ff (patch)
tree8c94d8970f1dbe14d45554c8346c5569a164fca0
parent77947830628cc4ea2f1bfcd67d0572b869eac0d9 (diff)
Issue #1988508 by katbailey: Stop pretending we support Symfony bundles when we really just have service providers.
-rw-r--r--core/includes/bootstrap.inc5
-rw-r--r--core/includes/install.core.inc8
-rw-r--r--core/includes/install.inc2
-rw-r--r--core/includes/update.inc11
-rw-r--r--core/lib/Drupal.php4
-rw-r--r--core/lib/Drupal/Core/CoreServiceProvider.php (renamed from core/lib/Drupal/Core/CoreBundle.php)18
-rw-r--r--core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php39
-rw-r--r--core/lib/Drupal/Core/DependencyInjection/ServiceModifierInterface.php18
-rw-r--r--core/lib/Drupal/Core/DependencyInjection/ServiceProviderInterface.php18
-rw-r--r--core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php (renamed from core/lib/Drupal/Core/DependencyInjection/UpdateBundle.php)16
-rw-r--r--core/lib/Drupal/Core/DrupalKernel.php225
-rw-r--r--core/lib/Drupal/Core/DrupalKernelInterface.php37
-rw-r--r--core/lib/Drupal/Core/Extension/ModuleHandler.php2
-rw-r--r--core/lib/Drupal/Core/Template/TwigExtension.php4
-rw-r--r--core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestBundle.php28
-rw-r--r--core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestServiceProvider.php36
-rw-r--r--core/modules/serialization/lib/Drupal/serialization/SerializationServiceProvider.php (renamed from core/modules/serialization/lib/Drupal/serialization/SerializationBundle.php)12
-rw-r--r--core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php4
-rw-r--r--core/modules/simpletest/lib/Drupal/simpletest/TestBase.php6
-rw-r--r--core/modules/simpletest/lib/Drupal/simpletest/TestServiceProvider.php (renamed from core/modules/simpletest/lib/Drupal/simpletest/TestBundle.php)11
-rw-r--r--core/modules/system/language.api.php2
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php58
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php20
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/DrupalKernel/ServiceDestructionTest.php14
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php58
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/System/IgnoreSlaveSubscriberTest.php2
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php2
-rw-r--r--core/modules/system/tests/modules/bundle_test/bundle_test.info.yml7
-rw-r--r--core/modules/system/tests/modules/bundle_test/bundle_test.services.yml9
-rw-r--r--core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php (renamed from core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestBundle.php)12
-rw-r--r--core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/ServiceProviderTestServiceProvider.php33
-rw-r--r--core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestClass.php (renamed from core/modules/system/tests/modules/bundle_test/lib/Drupal/bundle_test/TestClass.php)8
-rw-r--r--core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestFileUsage.php (renamed from core/modules/system/tests/modules/bundle_test/lib/Drupal/bundle_test/TestFileUsage.php)5
-rw-r--r--core/modules/system/tests/modules/service_provider_test/service_provider_test.info.yml7
-rw-r--r--core/modules/system/tests/modules/service_provider_test/service_provider_test.module (renamed from core/modules/system/tests/modules/bundle_test/bundle_test.module)0
-rw-r--r--core/modules/system/tests/modules/service_provider_test/service_provider_test.services.yml7
-rw-r--r--core/update.php2
37 files changed, 505 insertions, 245 deletions
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index cf0e3dd..a818c78 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -1889,8 +1889,7 @@ function drupal_handle_request($test_only = FALSE) {
exit;
}
- // @todo Figure out how best to handle the Kernel constructor parameters.
- $kernel = new DrupalKernel('prod', FALSE, drupal_classloader(), !$test_only);
+ $kernel = new DrupalKernel('prod', drupal_classloader(), !$test_only);
// @todo Remove this once everything in the bootstrap has been
// converted to services in the DIC.
@@ -2026,7 +2025,7 @@ function _drupal_bootstrap_kernel() {
// Normally, index.php puts a container in drupal_container() by creating a
// kernel. If there is no container yet, create one.
if (!drupal_container()) {
- $kernel = new DrupalKernel('prod', FALSE, drupal_classloader());
+ $kernel = new DrupalKernel('prod', drupal_classloader());
$kernel->boot();
}
}
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 77771d8..34936d0 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -4,14 +4,14 @@ use Drupal\Component\Utility\Crypt;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\DrupalKernel;
-use Drupal\Core\CoreBundle;
+use Drupal\Core\CoreServiceProvider;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Install\TaskException;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\StringTranslation\Translator\FileTranslation;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -354,7 +354,7 @@ function install_begin_request(&$install_state) {
// @see drupal_install_config_directories()
// @see install_settings_form_submit()
if ($install_state['settings_verified']) {
- $kernel = new DrupalKernel('install', FALSE, drupal_classloader(), FALSE);
+ $kernel = new DrupalKernel('install', drupal_classloader(), FALSE);
$kernel->boot();
$container = $kernel->getContainer();
// Add the file translation service to the container.
@@ -426,7 +426,7 @@ function install_begin_request(&$install_state) {
$conf['keyvalue_expirable_default'] = 'keyvalue.expirable.null';
// Register Twig template engine for use during install.
- CoreBundle::registerTwig($container);
+ CoreServiceProvider::registerTwig($container);
$container->register('url_generator', 'Drupal\Core\Routing\NullGenerator');
diff --git a/core/includes/install.inc b/core/includes/install.inc
index b0ca296..e0e86cc 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -619,7 +619,7 @@ function drupal_install_system() {
if (!drupal_container()->has('kernel')) {
// Immediately boot a kernel to have real services ready.
- $kernel = new DrupalKernel('install', FALSE, drupal_classloader(), FALSE);
+ $kernel = new DrupalKernel('install', drupal_classloader(), FALSE);
$kernel->boot();
}
diff --git a/core/includes/update.inc b/core/includes/update.inc
index 3659caf..fe83e31 100644
--- a/core/includes/update.inc
+++ b/core/includes/update.inc
@@ -103,10 +103,9 @@ function update_prepare_d8_bootstrap() {
$settings['cache']['default'] = 'cache.backend.memory';
new Settings($settings);
- // Enable UpdateBundle service overrides. While the container_bundles array
- // does not need a key, let's use so it can be removed once the upgrade are
- // finished. @see update_flush_all_caches()
- $GLOBALS['conf']['container_bundles']['UpdateBundle'] = 'Drupal\Core\DependencyInjection\UpdateBundle';
+ // Enable UpdateServiceProvider service overrides.
+ // @see update_flush_all_caches()
+ $GLOBALS['conf']['container_service_providers']['UpdateServiceProvider'] = 'Drupal\Core\DependencyInjection\UpdateServiceProvider';
// Check whether settings.php needs to be rewritten.
$settings_exist = !empty($GLOBALS['config_directories']);
@@ -117,7 +116,7 @@ function update_prepare_d8_bootstrap() {
// Bootstrap the kernel.
// Do not attempt to dump and write it.
- $kernel = new DrupalKernel('update', FALSE, drupal_classloader(), FALSE);
+ $kernel = new DrupalKernel('update', drupal_classloader(), FALSE);
$kernel->boot();
// If any of the required settings needs to be written, then settings.php
@@ -440,7 +439,7 @@ function update_prepare_d8_bootstrap() {
$settings = settings()->getAll();
unset($settings['cache']['default']);
new Settings($settings);
- $kernel = new DrupalKernel('update', FALSE, drupal_classloader(), FALSE);
+ $kernel = new DrupalKernel('update', drupal_classloader(), FALSE);
$kernel->boot();
}
diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php
index bb4368c..1fa80fc 100644
--- a/core/lib/Drupal.php
+++ b/core/lib/Drupal.php
@@ -19,8 +19,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* The container is built by the kernel and passed in to this class which stores
* it statically. The container always contains the services from
- * \Drupal\Core\CoreBundle, the bundles of enabled modules and any other bundles
- * defined in $GLOBALS['conf']['container_bundles'].
+ * \Drupal\Core\CoreServiceProvider, the service providers of enabled modules and any other
+ * service providers defined in $GLOBALS['conf']['container_service_providers'].
*
* This class exists only to support legacy code that cannot be dependency
* injected. If your code needs it, consider refactoring it to be object
diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreServiceProvider.php
index 9af0c74..310343e 100644
--- a/core/lib/Drupal/Core/CoreBundle.php
+++ b/core/lib/Drupal/Core/CoreServiceProvider.php
@@ -2,12 +2,15 @@
/**
* @file
- * Definition of Drupal\Core\CoreBundle.
+ * Definition of Drupal\Core\CoreServiceProvider.
*/
namespace Drupal\Core;
use Drupal\Core\Cache\ListCacheBinsPass;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\Compiler\ModifyServiceDefinitionsPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterKernelListenersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterAccessChecksPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterMatchersPass;
@@ -18,16 +21,14 @@ use Drupal\Core\DependencyInjection\Compiler\RegisterParamConvertersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterServicesForDestructionPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterStringTranslatorsPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterBreadcrumbBuilderPass;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Scope;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
/**
- * Bundle class for mandatory core services.
+ * ServiceProvider class for mandatory core services.
*
* This is where Drupal core registers all of its compiler passes.
* The service definitions themselves are in core/core.services.yml with a
@@ -36,12 +37,12 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig;
* Modules wishing to register services to the container should use
* modulename.services.yml in their respective directories.
*/
-class CoreBundle extends Bundle {
+class CoreServiceProvider implements ServiceProviderInterface {
/**
- * Implements \Symfony\Component\HttpKernel\Bundle\BundleInterface::build().
+ * {@inheritdoc}
*/
- public function build(ContainerBuilder $container) {
+ public function register(ContainerBuilder $container) {
// The 'request' scope and service enable services to depend on the Request
// object and get reconstructed when the request object changes (e.g.,
// during a subrequest).
@@ -67,6 +68,9 @@ class CoreBundle extends Bundle {
// Add the compiler pass that will process the tagged breadcrumb builder
// services.
$container->addCompilerPass(new RegisterBreadcrumbBuilderPass());
+ // Add the compiler pass that lets service providers modify existing
+ // service definitions.
+ $container->addCompilerPass(new ModifyServiceDefinitionsPass());
}
/**
diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php
new file mode 100644
index 0000000..25614e3
--- /dev/null
+++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\Core\DependencyInjection\Compiler\ModifyServiceDefinitionsPass.
+ */
+
+namespace Drupal\Core\DependencyInjection\Compiler;
+
+use Drupal\Core\DrupalKernelInterface;
+use Drupal\Core\DependencyInjection\ServiceModifierInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+
+/**
+ * Passes the container to the alter() method of all service providers.
+ */
+class ModifyServiceDefinitionsPass implements CompilerPassInterface {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function process(ContainerBuilder $container) {
+ if (!$container->has('kernel')) {
+ return;
+ }
+ $kernel = $container->get('kernel');
+ if (!($kernel instanceof DrupalKernelInterface)) {
+ return;
+ }
+ $providers = $kernel->getServiceProviders();
+ foreach ($providers as $provider) {
+ if ($provider instanceof ServiceModifierInterface) {
+ $provider->alter($container);
+ }
+ }
+ }
+
+}
diff --git a/core/lib/Drupal/Core/DependencyInjection/ServiceModifierInterface.php b/core/lib/Drupal/Core/DependencyInjection/ServiceModifierInterface.php
new file mode 100644
index 0000000..000366c
--- /dev/null
+++ b/core/lib/Drupal/Core/DependencyInjection/ServiceModifierInterface.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Drupal\Core\DependencyInjection;
+
+/**
+ * Interface that service providers can implement to modify services.
+ */
+interface ServiceModifierInterface {
+
+ /**
+ * Modifies existing service definitions.
+ *
+ * @param ContainerBuilder $container
+ * The ContainerBuilder whose service definitions can be altered.
+ */
+ public function alter(ContainerBuilder $container);
+
+}
diff --git a/core/lib/Drupal/Core/DependencyInjection/ServiceProviderInterface.php b/core/lib/Drupal/Core/DependencyInjection/ServiceProviderInterface.php
new file mode 100644
index 0000000..98d1f02
--- /dev/null
+++ b/core/lib/Drupal/Core/DependencyInjection/ServiceProviderInterface.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Drupal\Core\DependencyInjection;
+
+/**
+ * Interface that all service providers must implement.
+ */
+interface ServiceProviderInterface {
+
+ /**
+ * Registers services to the container.
+ *
+ * @param ContainerBuilder $container
+ * The ContainerBuilder to register services to.
+ */
+ public function register(ContainerBuilder $container);
+
+}
diff --git a/core/lib/Drupal/Core/DependencyInjection/UpdateBundle.php b/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php
index 91528e5..d458665 100644
--- a/core/lib/Drupal/Core/DependencyInjection/UpdateBundle.php
+++ b/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php
@@ -2,27 +2,27 @@
/**
* @file
- * Contains \Drupal\Core\DependencyInjection\UpdateBundle.
+ * Contains \Drupal\Core\DependencyInjection\UpdateServiceProvider.
*/
namespace Drupal\Core\DependencyInjection;
-use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
/**
- * Bundle class for update.php service overrides.
+ * ServiceProvider class for update.php service overrides.
*
- * This bundle is manually added by update.php via $conf['container_bundles']
+ * This class is manually added by update.php via $conf['container_service_providers']
* and required to prevent various services from trying to retrieve data from
* storages that do not exist yet.
*/
-class UpdateBundle extends Bundle {
+class UpdateServiceProvider implements ServiceProviderInterface {
/**
- * Implements \Symfony\Component\HttpKernel\Bundle\BundleInterface::build().
+ * {@inheritdoc}
*/
- public function build(SymfonyContainerBuilder $container) {
+ public function register(ContainerBuilder $container) {
// Disable the Lock service.
$container
->register('lock', 'Drupal\Core\Lock\NullLockBackend');
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 6d7d4fa..af1fe52 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -9,26 +9,55 @@ namespace Drupal\Core;
use Drupal\Component\PhpStorage\PhpStorageFactory;
use Drupal\Core\Config\BootstrapConfigStorageFactory;
-use Drupal\Core\CoreBundle;
+use Drupal\Core\CoreServiceProvider;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\YamlFileLoader;
use Symfony\Component\ClassLoader\ClassLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
-use Symfony\Component\HttpKernel\Kernel;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpKernel\TerminableInterface;
/**
* The DrupalKernel class is the core of Drupal itself.
*
* This class is responsible for building the Dependency Injection Container and
- * also deals with the registration of bundles. It allows registered bundles to
- * add their services to the container. Core provides the CoreBundle, which adds
- * the services required for all core subsystems. Each module can then add its
- * own bundle, i.e. a subclass of Symfony\Component\HttpKernel\Bundle, to
- * register services to the container.
+ * also deals with the registration of service providers. It allows registered
+ * service providers to add their services to the container. Core provides the
+ * CoreServiceProvider, which, in addition to registering any core services that
+ * cannot be registered in the core.services.yaml file, adds any compiler passes
+ * needed by core, e.g. for processing tagged services. Each module can add its
+ * own service provider, i.e. a class implementing
+ * Drupal\Core\DependencyInjection\ServiceProvider, to register services to the
+ * container, or modify existing services.
*/
-class DrupalKernel extends Kernel implements DrupalKernelInterface {
+class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
+
+ const CONTAINER_BASE_CLASS = 'Container';
+
+ /**
+ * Holds the container instance.
+ *
+ * @var \Symfony\Component\DependencyInjection\ContainerInterface
+ */
+ protected $container;
+
+ /**
+ * The environment, e.g. 'testing', 'install'.
+ *
+ * @var string
+ */
+ protected $environment;
+
+ /**
+ * Whether the kernel has been booted.
+ *
+ * @var bool
+ */
+ protected $booted;
/**
* Holds the list of enabled modules.
@@ -80,11 +109,11 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
protected $configStorage;
/**
- * The list of the classnames of the bundles in this kernel.
+ * The list of the classnames of the service providers in this kernel.
*
* @var array
*/
- protected $bundleClasses;
+ protected $serviceProviderClasses;
/**
* Whether the container can be dumped.
@@ -108,27 +137,31 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
protected $serviceYamls;
/**
+ * The array of registered service providers.
+ *
+ * @var array
+ */
+ protected $serviceProviders;
+
+ /**
* Constructs a DrupalKernel object.
*
* @param string $environment
* String indicating the environment, e.g. 'prod' or 'dev'. Used by
* Symfony\Component\HttpKernel\Kernel::__construct(). Drupal does not use
* this value currently. Pass 'prod'.
- * @param bool $debug
- * Boolean indicating whether we are in debug mode. Used by
- * Symfony\Component\HttpKernel\Kernel::__construct(). Drupal does not use
- * this value currently. Pass TRUE.
* @param \Symfony\Component\ClassLoader\ClassLoader $class_loader
* (optional) The classloader is only used if $storage is not given or
* the load from storage fails and a container rebuild is required. In
* this case, the loaded modules will be registered with this loader in
- * order to be able to find the module bundles.
+ * order to be able to find the module serviceProviders.
* @param bool $allow_dumping
* (optional) FALSE to stop the container from being written to or read
* from disk. Defaults to TRUE.
*/
- public function __construct($environment, $debug, ClassLoader $class_loader, $allow_dumping = TRUE) {
- parent::__construct($environment, $debug);
+ public function __construct($environment, ClassLoader $class_loader, $allow_dumping = TRUE) {
+ $this->environment = $environment;
+ $this->booted = false;
$this->classLoader = $class_loader;
$this->allowDumping = $allow_dumping;
}
@@ -137,29 +170,19 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
* {@inheritdoc}
*/
public function serialize() {
- return serialize(array($this->environment, $this->debug, $this->classLoader, $this->allowDumping));
+ return serialize(array($this->environment, $this->classLoader, $this->allowDumping));
}
/**
* {@inheritdoc}
*/
public function unserialize($data) {
- list($environment, $debug, $class_loader, $allow_dumping) = unserialize($data);
- $this->__construct($environment, $debug, $class_loader, $allow_dumping);
- }
-
- /**
- * Overrides Kernel::init().
- */
- public function init() {
- // Intentionally empty. The sole purpose is to not execute Kernel::init(),
- // since that overrides/breaks Drupal's current error handling.
- // @todo Investigate whether it is possible to migrate Drupal's error
- // handling to the one of Kernel without losing functionality.
+ list($environment, $class_loader, $allow_dumping) = unserialize($data);
+ $this->__construct($environment, $class_loader, $allow_dumping);
}
/**
- * Overrides Kernel::boot().
+ * {@inheritdoc}
*/
public function boot() {
if ($this->booted) {
@@ -167,26 +190,41 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
}
$this->initializeContainer();
$this->booted = TRUE;
- if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, $this->getContainerBaseClass())) {
+ if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, static::CONTAINER_BASE_CLASS)) {
watchdog('DrupalKernel', 'Container cannot be written to disk');
}
}
/**
- * Returns an array of available bundles.
- *
- * @return array
- * The available bundles.
+ * {@inheritdoc}
*/
- public function registerBundles() {
+ public function shutdown() {
+ if (FALSE === $this->booted) {
+ return;
+ }
+ $this->booted = FALSE;
+ $this->container = null;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getContainer() {
+ return $this->container;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function discoverServiceProviders() {
$this->configStorage = BootstrapConfigStorageFactory::get();
- $bundles = array(
- new CoreBundle(),
+ $serviceProviders = array(
+ 'CoreServiceProvider' => new CoreServiceProvider(),
);
$this->serviceYamls = array(
'core/core.services.yml'
);
- $this->bundleClasses = array('Drupal\Core\CoreBundle');
+ $this->serviceProviderClasses = array('Drupal\Core\CoreServiceProvider');
// Ensure we know what modules are enabled and that their namespaces are
// registered.
@@ -197,13 +235,14 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
$module_filenames = $this->getModuleFileNames();
$this->registerNamespaces($this->getModuleNamespaces($module_filenames));
- // Load each module's bundle class.
+ // Load each module's serviceProvider class.
foreach ($this->moduleList as $module => $weight) {
$camelized = ContainerBuilder::camelize($module);
- $class = "Drupal\\{$module}\\{$camelized}Bundle";
+ $name = "{$camelized}ServiceProvider";
+ $class = "Drupal\\{$module}\\{$name}";
if (class_exists($class)) {
- $bundles[] = new $class();
- $this->bundleClasses[] = $class;
+ $serviceProviders[$name] = new $class();
+ $this->serviceProviderClasses[] = $class;
}
$filename = dirname($module_filenames[$module]) . "/$module.services.yml";
if (file_exists($filename)) {
@@ -211,18 +250,50 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
}
}
- // Add site specific or test bundles.
- if (!empty($GLOBALS['conf']['container_bundles'])) {
- foreach ($GLOBALS['conf']['container_bundles'] as $class) {
- $bundles[] = new $class();
- $this->bundleClasses[] = $class;
+ // Add site specific or test service providers.
+ if (!empty($GLOBALS['conf']['container_service_providers'])) {
+ foreach ($GLOBALS['conf']['container_service_providers'] as $name => $class) {
+ $serviceProviders[$name] = new $class();
+ $this->serviceProviderClasses[] = $class;
}
}
// Add site specific or test YAMLs.
if (!empty($GLOBALS['conf']['container_yamls'])) {
$this->serviceYamls = array_merge($this->serviceYamls, $GLOBALS['conf']['container_yamls']);
}
- return $bundles;
+ return $serviceProviders;
+ }
+
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getServiceProviders() {
+ return $this->serviceProviders;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function terminate(Request $request, Response $response) {
+ if (FALSE === $this->booted) {
+ return;
+ }
+
+ if ($this->getHttpKernel() instanceof TerminableInterface) {
+ $this->getHttpKernel()->terminate($request, $response);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) {
+ if (FALSE === $this->booted) {
+ $this->boot();
+ }
+
+ return $this->getHttpKernel()->handle($request, $type, $catch);
}
/**
@@ -269,7 +340,7 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
}
// If we haven't yet booted, we don't need to do anything: the new module
// list will take effect when boot() is called. If we have already booted,
- // then reboot in order to refresh the bundle list and container.
+ // then reboot in order to refresh the serviceProvider list and container.
if ($this->booted) {
$this->booted = FALSE;
$this->boot();
@@ -277,13 +348,13 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
}
/**
- * Returns the classname based on environment, debug and testing prefix.
+ * Returns the classname based on environment and testing prefix.
*
* @return string
* The class name.
*/
protected function getClassName() {
- $parts = array('service_container', $this->environment, $this->debug);
+ $parts = array('service_container', $this->environment);
// Make sure to use a testing-specific container even in the parent site.
if (!empty($GLOBALS['drupal_test_info']['test_run_id'])) {
$parts[] = $GLOBALS['drupal_test_info']['test_run_id'];
@@ -294,6 +365,18 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
return implode('_', $parts);
}
+
+ /**
+ * Returns the kernel parameters.
+ *
+ * @return array An array of kernel parameters
+ */
+ protected function getKernelParameters() {
+ return array(
+ 'kernel.environment' => $this->environment,
+ );
+ }
+
/**
* Initializes the service container.
*/
@@ -371,6 +454,7 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
}
$this->container->set('kernel', $this);
+
// Set the class loader which was registered as a synthetic service.
$this->container->set('class_loader', $this->classLoader);
// If we have a request set it back to the new container.
@@ -416,9 +500,10 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
* @return ContainerBuilder The compiled service container
*/
protected function buildContainer() {
- $this->initializeBundles();
+ $this->initializeServiceProviders();
$container = $this->getContainerBuilder();
- $container->setParameter('container.bundles', $this->bundleClasses);
+ $container->set('kernel', $this);
+ $container->setParameter('container.service_providers', $this->serviceProviderClasses);
$container->setParameter('container.modules', $this->getModuleFileNames());
// Get a list of namespaces and put it onto the container.
@@ -443,8 +528,8 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
foreach ($this->serviceYamls as $filename) {
$yaml_loader->load($filename);
}
- foreach ($this->bundles as $bundle) {
- $bundle->build($container);
+ foreach ($this->serviceProviders as $provider) {
+ $provider->register($container);
}
// Identify all services whose instances should be persisted when rebuilding
@@ -464,6 +549,22 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
}
/**
+ * Registers all service providers to the kernel.
+ *
+ * @throws \LogicException
+ */
+ protected function initializeServiceProviders() {
+ $this->serviceProviders = array();
+
+ foreach ($this->discoverServiceProviders() as $name => $provider) {
+ if (isset($this->serviceProviders[$name])) {
+ throw new \LogicException(sprintf('Trying to register two service providers with the same name "%s"', $name));
+ }
+ $this->serviceProviders[$name] = $provider;
+ }
+ }
+
+ /**
* Gets a new ContainerBuilder instance used to build the service container.
*
* @return ContainerBuilder
@@ -497,6 +598,16 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface {
return $this->storage()->save($class . '.php', $content);
}
+
+ /**
+ * Gets a http kernel from the container
+ *
+ * @return HttpKernel
+ */
+ protected function getHttpKernel() {
+ return $this->container->get('http_kernel');
+ }
+
/**
* Overrides and eliminates this method from the parent class. Do not use.
*
diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php
index 60d0403..96b2f92 100644
--- a/core/lib/Drupal/Core/DrupalKernelInterface.php
+++ b/core/lib/Drupal/Core/DrupalKernelInterface.php
@@ -7,7 +7,7 @@
namespace Drupal\Core;
-use Symfony\Component\HttpKernel\KernelInterface;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* The interface for DrupalKernel, the core of Drupal.
@@ -15,7 +15,40 @@ use Symfony\Component\HttpKernel\KernelInterface;
* This interface extends Symfony's KernelInterface and adds methods for
* responding to modules being enabled or disabled during its lifetime.
*/
-interface DrupalKernelInterface extends KernelInterface {
+interface DrupalKernelInterface extends HttpKernelInterface, \Serializable {
+
+ /**
+ * Boots the current kernel.
+ */
+ public function boot();
+
+ /**
+ * Shuts down the kernel.
+ */
+ public function shutdown();
+
+ /**
+ * Discovers available serviceProviders.
+ *
+ * @return array
+ * The available serviceProviders.
+ */
+ public function discoverServiceProviders();
+
+ /**
+ * Returns all registered service providers.
+ *
+ * @return array
+ * An associative array of ServiceProvider objects, keyed by name.
+ */
+ public function getServiceProviders();
+
+ /**
+ * Gets the current container.
+ *
+ * @return ContainerInterface A ContainerInterface instance
+ */
+ public function getContainer();
/**
* Updates the kernel's list of modules to the new list.
diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php
index 656e918..c510192 100644
--- a/core/lib/Drupal/Core/Extension/ModuleHandler.php
+++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php
@@ -81,7 +81,7 @@ class ModuleHandler implements ModuleHandlerInterface {
* %container.modules% parameter being set up by DrupalKernel.
*
* @see \Drupal\Core\DrupalKernel
- * @see \Drupal\Core\CoreBundle
+ * @see \Drupal\Core\CoreServiceProvider
*/
public function __construct(array $module_list = array()) {
$this->moduleList = $module_list;
diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php
index 898fdf8..3c86bd1 100644
--- a/core/lib/Drupal/Core/Template/TwigExtension.php
+++ b/core/lib/Drupal/Core/Template/TwigExtension.php
@@ -6,7 +6,7 @@
*
* This provides a Twig extension that registers various Drupal specific extensions to Twig.
*
- * @see \Drupal\Core\CoreBundle
+ * @see \Drupal\Core\CoreServiceProvider
*/
namespace Drupal\Core\Template;
@@ -14,7 +14,7 @@ namespace Drupal\Core\Template;
/**
* A class for providing Twig extensions (specific Twig_NodeVisitors, filters and functions).
*
- * @see \Drupal\Core\CoreBundle
+ * @see \Drupal\Core\CoreServiceProvider
*/
class TwigExtension extends \Twig_Extension {
public function getFunctions() {
diff --git a/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestBundle.php b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestBundle.php
deleted file mode 100644
index b711507..0000000
--- a/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestBundle.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\language_test\LanguageTestBundle.
- */
-
-namespace Drupal\language_test;
-
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
-
-/**
- * Defines the LanguageTest bundle.
- */
-class LanguageTestBundle extends Bundle {
-
- /**
- * Overrides \Symfony\Component\HttpKernel\Bundle\Bundle::build().
- */
- public function build(ContainerBuilder $container) {
- // Overrides language_manager class to test domain language negotiation.
- $definition = $container->getDefinition('language_manager');
- $definition->setClass('Drupal\language_test\LanguageTestManager');
- }
-
-}
-
diff --git a/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestServiceProvider.php b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestServiceProvider.php
new file mode 100644
index 0000000..c8b1633
--- /dev/null
+++ b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestServiceProvider.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\language_test\LanguageTestServiceProvider.
+ */
+
+namespace Drupal\language_test;
+
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceModifierInterface;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
+
+/**
+ * Defines the LanguageTest service provider.
+ */
+class LanguageTestServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function register(ContainerBuilder $container) {
+
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function alter(ContainerBuilder $container) {
+ // Overrides language_manager class to test domain language negotiation.
+ $definition = $container->getDefinition('language_manager');
+ $definition->setClass('Drupal\language_test\LanguageTestManager');
+ }
+
+}
+
diff --git a/core/modules/serialization/lib/Drupal/serialization/SerializationBundle.php b/core/modules/serialization/lib/Drupal/serialization/SerializationServiceProvider.php
index f649052..2e89e5c 100644
--- a/core/modules/serialization/lib/Drupal/serialization/SerializationBundle.php
+++ b/core/modules/serialization/lib/Drupal/serialization/SerializationServiceProvider.php
@@ -2,23 +2,23 @@
/**
* @file
- * Contains \Drupal\serialization\SerializationBundle.
+ * Contains \Drupal\serialization\SerializationServiceProvider.
*/
namespace Drupal\serialization;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
/**
* Serialization dependency injection container.
*/
-class SerializationBundle extends Bundle {
+class SerializationServiceProvider implements ServiceProviderInterface {
/**
- * Overrides \Symfony\Component\HttpKernel\Bundle\Bundle::build().
+ * {@inheritdoc}
*/
- public function build(ContainerBuilder $container) {
+ public function register(ContainerBuilder $container) {
// Add a compiler pass for adding Normalizers and Encoders to Serializer.
$container->addCompilerPass(new RegisterSerializationClassesCompilerPass());
// Add a compiler pass for adding concrete Resolvers to chain Resolver.
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
index 2c80dcd..e54e121 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
@@ -90,7 +90,7 @@ abstract class DrupalUnitTestBase extends UnitTestBase {
// Build a minimal, partially mocked environment for unit tests.
$this->containerBuild(drupal_container());
// Make sure it survives kernel rebuilds.
- $GLOBALS['conf']['container_bundles'][] = 'Drupal\simpletest\TestBundle';
+ $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider';
\Drupal::state()->set('system.module.files', $this->moduleFiles);
\Drupal::state()->set('system.theme.files', $this->themeFiles);
@@ -98,7 +98,7 @@ abstract class DrupalUnitTestBase extends UnitTestBase {
// Bootstrap the kernel.
// No need to dump it; this test runs in-memory.
- $this->kernel = new DrupalKernel('unit_testing', TRUE, drupal_classloader(), FALSE);
+ $this->kernel = new DrupalKernel('unit_testing', drupal_classloader(), FALSE);
$this->kernel->boot();
// Collect and set a fixed module list.
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 1b746e6..818b7b0 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -698,7 +698,7 @@ abstract class TestBase {
* methods during debugging.
*/
public function run(array $methods = array()) {
- TestBundle::$currentTest = $this;
+ TestServiceProvider::$currentTest = $this;
$simpletest_config = config('simpletest.settings');
$class = get_class($this);
@@ -770,7 +770,7 @@ abstract class TestBase {
}
}
}
- TestBundle::$currentTest = NULL;
+ TestServiceProvider::$currentTest = NULL;
// Clear out the error messages and restore error handler.
drupal_get_messages();
restore_error_handler();
@@ -993,7 +993,7 @@ abstract class TestBase {
* @see TestBase::tearDown()
*/
protected function rebuildContainer() {
- $this->kernel = new DrupalKernel('testing', FALSE, drupal_classloader(), FALSE);
+ $this->kernel = new DrupalKernel('testing', drupal_classloader(), FALSE);
$this->kernel->boot();
// DrupalKernel replaces the container in drupal_container() with a
// different object, so we need to replace the instance on this test class.
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBundle.php b/core/modules/simpletest/lib/Drupal/simpletest/TestServiceProvider.php
index 7e2fd2f..9b26f12 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBundle.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestServiceProvider.php
@@ -2,10 +2,10 @@
namespace Drupal\simpletest;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
-class TestBundle extends Bundle {
+class TestServiceProvider implements ServiceProviderInterface {
/**
* @var \Drupal\simpletest\TestBase;
@@ -13,12 +13,11 @@ class TestBundle extends Bundle {
public static $currentTest;
/**
- * Implements \Symfony\Component\HttpKernel\Bundle\BundleInterface::build().
+ * {@inheritdoc}
*/
- function build(ContainerBuilder $container) {
+ function register(ContainerBuilder $container) {
if (static::$currentTest && method_exists(static::$currentTest, 'containerBuild')) {
static::$currentTest->containerBuild($container);
}
}
-
}
diff --git a/core/modules/system/language.api.php b/core/modules/system/language.api.php
index fb165a4..7f4b0c2 100644
--- a/core/modules/system/language.api.php
+++ b/core/modules/system/language.api.php
@@ -201,7 +201,7 @@ function hook_language_fallback_candidates_alter(array &$fallback_candidates) {
* hook_transliteration_overrides_alter() to provide further language-specific
* overrides (including providing transliteration for Unicode characters that
* are longer than 4 bytes). Modules can also completely override the
- * transliteration classes in \Drupal\Core\CoreBundle.
+ * transliteration classes in \Drupal\Core\CoreServiceProvider.
*/
/**
diff --git a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php b/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php
deleted file mode 100644
index 35faa3c..0000000
--- a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-/**
- * @file
- * Definition of Drupal\system\Tests\Bundle\BundleTest.
- */
-
-namespace Drupal\system\Tests\Bundle;
-
-use Drupal\simpletest\WebTestBase;
-
-/**
- * Tests bundle registration to the DIC.
- */
-class BundleTest extends WebTestBase {
-
- /**
- * Modules to enable.
- *
- * @var array
- */
- public static $modules = array('bundle_test');
-
- public static function getInfo() {
- return array(
- 'name' => 'Bundle Registration',
- 'description' => 'Tests bundle registration to the DIC.',
- 'group' => 'Bundle',
- );
- }
-
- /**
- * Tests that services provided by module bundles get registered to the DIC.
- */
- function testBundleRegistration() {
- $this->assertTrue(drupal_container()->getDefinition('file.usage')->getClass() == 'Drupal\\bundle_test\\TestFileUsage', 'Class has been changed');
- $this->assertTrue(drupal_container()->has('bundle_test_class'), 'The bundle_test_class service has been registered to the DIC');
- // The event subscriber method in the test class calls drupal_set_message with
- // a message saying it has fired. This will fire on every page request so it
- // should show up on the front page.
- $this->drupalGet('');
- $this->assertText(t('The bundle_test event subscriber fired!'), 'The bundle_test event subscriber fired');
- }
-
- /**
- * Tests that the DIC keeps up with module enable/disable in the same request.
- */
- function testBundleRegistrationDynamic() {
- // Disable the module and ensure the bundle's service is not registered.
- module_disable(array('bundle_test'));
- $this->assertFalse(drupal_container()->has('bundle_test_class'), 'The bundle_test_class service does not exist in the DIC.');
-
- // Enable the module and ensure the bundle's service is registered.
- module_enable(array('bundle_test'));
- $this->assertTrue(drupal_container()->has('bundle_test_class'), 'The bundle_test_class service exists in the DIC.');
- }
-
-}
diff --git a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php
index 87c7019..db60d18 100644
--- a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php
@@ -49,12 +49,12 @@ class DrupalKernelTest extends UnitTestBase {
'system' => 'system',
'user' => 'user',
);
- $kernel = new DrupalKernel('testing', FALSE, $classloader);
+ $kernel = new DrupalKernel('testing', $classloader);
$kernel->updateModules($module_enabled);
$kernel->boot();
// Instantiate it a second time and we should get the compiled Container
// class.
- $kernel = new DrupalKernel('testing', FALSE, $classloader);
+ $kernel = new DrupalKernel('testing', $classloader);
$kernel->updateModules($module_enabled);
$kernel->boot();
$container = $kernel->getContainer();
@@ -68,7 +68,7 @@ class DrupalKernelTest extends UnitTestBase {
// environment.
global $conf;
$conf['php_storage']['service_container']['class'] = 'Drupal\Component\PhpStorage\FileReadOnlyStorage';
- $kernel = new DrupalKernel('testing', FALSE, $classloader);
+ $kernel = new DrupalKernel('testing', $classloader);
$kernel->updateModules($module_enabled);
$kernel->boot();
$container = $kernel->getContainer();
@@ -86,17 +86,17 @@ class DrupalKernelTest extends UnitTestBase {
// is functioning correctly, i.e. we get a brand new ContainerBuilder
// which has the required new services, after changing the list of enabled
// modules.
- $this->assertFalse($container->has('bundle_test_class'));
+ $this->assertFalse($container->has('service_provider_test_class'));
// Add another module so that we can test that the new module's bundle is
// registered to the new container.
- $module_enabled['bundle_test'] = 'bundle_test';
- $kernel = new DrupalKernel('testing', FALSE, $classloader);
+ $module_enabled['service_provider_test'] = 'service_provider_test';
+ $kernel = new DrupalKernel('testing', $classloader);
$kernel->updateModules($module_enabled);
$kernel->boot();
// Instantiate it a second time and we should still get a ContainerBuilder
// class because we are using the read-only PHP storage.
- $kernel = new DrupalKernel('testing', FALSE, $classloader);
+ $kernel = new DrupalKernel('testing', $classloader);
$kernel->updateModules($module_enabled);
$kernel->boot();
$container = $kernel->getContainer();
@@ -104,14 +104,14 @@ class DrupalKernelTest extends UnitTestBase {
$is_container_builder = $refClass->isSubclassOf('Symfony\Component\DependencyInjection\ContainerBuilder');
$this->assertTrue($is_container_builder);
// Assert that the new module's bundle was registered to the new container.
- $this->assertTrue($container->has('bundle_test_class'));
+ $this->assertTrue($container->has('service_provider_test_class'));
// Test that our synthetic services are there.
$classloader = $container->get('class_loader');
$refClass = new ReflectionClass($classloader);
$this->assertTrue($refClass->hasMethod('loadClass'), 'Container has a classloader');
// Check that the location of the new module is registered.
$modules = $container->getParameter('container.modules');
- $this->assertEqual($modules['bundle_test'], drupal_get_filename('module', 'bundle_test'));
+ $this->assertEqual($modules['service_provider_test'], drupal_get_filename('module', 'service_provider_test'));
}
/**
@@ -119,7 +119,7 @@ class DrupalKernelTest extends UnitTestBase {
*/
public function testSerialization() {
$classloader = drupal_classloader();
- $kernel = new DrupalKernel('testing', FALSE, $classloader);
+ $kernel = new DrupalKernel('testing', $classloader);
$string = serialize($kernel);
$unserialized_kernel = unserialize($string);
diff --git a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/ServiceDestructionTest.php b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/ServiceDestructionTest.php
index 9bfde63..a48e883 100644
--- a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/ServiceDestructionTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/ServiceDestructionTest.php
@@ -29,16 +29,16 @@ class ServiceDestructionTest extends DrupalUnitTestBase {
*/
public function testDestructionUsed() {
// Enable the test module to add it to the container.
- $this->enableModules(array('bundle_test'));
+ $this->enableModules(array('service_provider_test'));
// The service has not been destructed yet.
- $this->assertNull(\Drupal::state()->get('bundle_test.destructed'));
+ $this->assertNull(\Drupal::state()->get('service_provider_test.destructed'));
// Call the class and then terminate the kernel
- $this->container->get('bundle_test_class');
+ $this->container->get('service_provider_test_class');
$response = new Response();
$this->container->get('kernel')->terminate($this->container->get('request'), $response);
- $this->assertTrue(\Drupal::state()->get('bundle_test.destructed'));
+ $this->assertTrue(\Drupal::state()->get('service_provider_test.destructed'));
}
/**
@@ -46,15 +46,15 @@ class ServiceDestructionTest extends DrupalUnitTestBase {
*/
public function testDestructionUnused() {
// Enable the test module to add it to the container.
- $this->enableModules(array('bundle_test'));
+ $this->enableModules(array('service_provider_test'));
// The service has not been destructed yet.
- $this->assertNull(\Drupal::state()->get('bundle_test.destructed'));
+ $this->assertNull(\Drupal::state()->get('service_provider_test.destructed'));
// Terminate the kernel. The test class has not been called, so it should not
// be destructed.
$response = new Response();
$this->container->get('kernel')->terminate($this->container->get('request'), $response);
- $this->assertNull(\Drupal::state()->get('bundle_test.destructed'));
+ $this->assertNull(\Drupal::state()->get('service_provider_test.destructed'));
}
}
diff --git a/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php b/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php
new file mode 100644
index 0000000..bffd0f0
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\system\Tests\ServiceProvider\ServiceProviderTest.
+ */
+
+namespace Drupal\system\Tests\ServiceProvider;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests service provider registration to the DIC.
+ */
+class ServiceProviderTest extends WebTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('file', 'service_provider_test');
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Service Provider Registration',
+ 'description' => 'Tests service provider registration to the DIC.',
+ 'group' => 'Service Provider',
+ );
+ }
+
+ /**
+ * Tests that services provided by module service providers get registered to the DIC.
+ */
+ function testServiceProviderRegistration() {
+ $this->assertTrue(drupal_container()->getDefinition('file.usage')->getClass() == 'Drupal\\service_provider_test\\TestFileUsage', 'Class has been changed');
+ $this->assertTrue(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC');
+ // The event subscriber method in the test class calls drupal_set_message with
+ // a message saying it has fired. This will fire on every page request so it
+ // should show up on the front page.
+ $this->drupalGet('');
+ $this->assertText(t('The service_provider_test event subscriber fired!'), 'The service_provider_test event subscriber fired');
+ }
+
+ /**
+ * Tests that the DIC keeps up with module enable/disable in the same request.
+ */
+ function testServiceProviderRegistrationDynamic() {
+ // Disable the module and ensure the service provider's service is not registered.
+ module_disable(array('service_provider_test'));
+ $this->assertFalse(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service does not exist in the DIC.');
+
+ // Enable the module and ensure the service provider's service is registered.
+ module_enable(array('service_provider_test'));
+ $this->assertTrue(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.');
+ }
+
+}
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/IgnoreSlaveSubscriberTest.php b/core/modules/system/lib/Drupal/system/Tests/System/IgnoreSlaveSubscriberTest.php
index bf004f9..da65377 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/IgnoreSlaveSubscriberTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/IgnoreSlaveSubscriberTest.php
@@ -38,7 +38,7 @@ class IgnoreSlaveSubscriberTest extends UnitTestBase {
Database::addConnectionInfo('default', 'slave', $connection_info['default']);
db_ignore_slave();
- $kernel = new DrupalKernel('testing', FALSE, drupal_classloader(), FALSE);
+ $kernel = new DrupalKernel('testing', drupal_classloader(), FALSE);
$event = new GetResponseEvent($kernel, Request::create('http://example.com'), HttpKernelInterface::MASTER_REQUEST);
$subscriber = new SlaveDatabaseIgnoreSubscriber();
$subscriber->checkSlaveServer($event);
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
index b613121..8a1cb68 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
@@ -114,7 +114,7 @@ abstract class UpgradePathTestBase extends WebTestBase {
// Build a minimal, partially mocked environment for unit tests.
$this->containerBuild(drupal_container());
// Make sure it survives kernel rebuilds.
- $conf['container_bundles'][] = 'Drupal\simpletest\TestBundle';
+ $conf['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider';
// Change the database prefix.
// All static variables need to be reset before the database prefix is
diff --git a/core/modules/system/tests/modules/bundle_test/bundle_test.info.yml b/core/modules/system/tests/modules/bundle_test/bundle_test.info.yml
deleted file mode 100644
index 49335fb..0000000
--- a/core/modules/system/tests/modules/bundle_test/bundle_test.info.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-name: 'Bundle test'
-type: module
-description: 'Support module for bundle testing.'
-package: Testing
-version: VERSION
-core: 8.x
-hidden: true
diff --git a/core/modules/system/tests/modules/bundle_test/bundle_test.services.yml b/core/modules/system/tests/modules/bundle_test/bundle_test.services.yml
deleted file mode 100644
index 88b3caf..0000000
--- a/core/modules/system/tests/modules/bundle_test/bundle_test.services.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-services:
- bundle_test_class:
- class: Drupal\bundle_test\TestClass
- tags:
- - { name: event_subscriber }
- - { name: needs_destruction }
- arguments: ['@state']
- file.usage:
- class: Drupal\bundle_test\TestFileUsage
diff --git a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestBundle.php b/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php
index 114ddf4..9c1dbc3 100644
--- a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestBundle.php
+++ b/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php
@@ -2,23 +2,23 @@
/**
* @file
- * Definition of \Drupal\router_test\RouterTestBundle.
+ * Definition of \Drupal\router_test\RouterTestServiceProvider.
*/
namespace Drupal\router_test;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
/**
* Registers a dynamic route provider.
*/
-class RouterTestBundle extends Bundle {
+class RouterTestServiceProvider implements ServiceProviderInterface {
/**
- * Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build().
+ * {@inheritdoc}
*/
- public function build(ContainerBuilder $container) {
+ public function register(ContainerBuilder $container) {
$container->register('router_test.subscriber', 'Drupal\router_test\RouteTestSubscriber')->addTag('event_subscriber');
$container->register('access_check.router_test', 'Drupal\router_test\Access\TestAccessCheck')
->addTag('access_check');
diff --git a/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/ServiceProviderTestServiceProvider.php b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/ServiceProviderTestServiceProvider.php
new file mode 100644
index 0000000..b2b85cb
--- /dev/null
+++ b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/ServiceProviderTestServiceProvider.php
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\service_provider_test\ServiceProviderTestServiceProvider.
+ */
+
+namespace Drupal\service_provider_test;
+
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
+use Drupal\Core\DependencyInjection\ServiceModifierInterface;
+
+class ServiceProviderTestServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function register(ContainerBuilder $container) {
+
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function alter(ContainerBuilder $container) {
+ if ($container->has('file.usage')) {
+ // Override the class used for the file.usage service.
+ $definition = $container->getDefinition('file.usage');
+ $definition->setClass('Drupal\service_provider_test\TestFileUsage');
+ }
+ }
+}
diff --git a/core/modules/system/tests/modules/bundle_test/lib/Drupal/bundle_test/TestClass.php b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestClass.php
index ad711cb..1c8ea06 100644
--- a/core/modules/system/tests/modules/bundle_test/lib/Drupal/bundle_test/TestClass.php
+++ b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestClass.php
@@ -2,10 +2,10 @@
/**
* @file
- * Definition of Drupal\bundle_test\TestClass.
+ * Definition of Drupal\service_provider_test\TestClass.
*/
-namespace Drupal\bundle_test;
+namespace Drupal\service_provider_test;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\Core\DestructableInterface;
@@ -36,7 +36,7 @@ class TestClass implements EventSubscriberInterface, DestructableInterface {
* A simple kernel listener method.
*/
public function onKernelRequestTest(GetResponseEvent $event) {
- drupal_set_message(t('The bundle_test event subscriber fired!'));
+ drupal_set_message(t('The service_provider_test event subscriber fired!'));
}
/**
@@ -54,6 +54,6 @@ class TestClass implements EventSubscriberInterface, DestructableInterface {
* Implements \Drupal\Core\DestructableInterface::destruct().
*/
public function destruct() {
- $this->state->set('bundle_test.destructed', TRUE);
+ $this->state->set('service_provider_test.destructed', TRUE);
}
}
diff --git a/core/modules/system/tests/modules/bundle_test/lib/Drupal/bundle_test/TestFileUsage.php b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestFileUsage.php
index 0ee5f2d..93919dc 100644
--- a/core/modules/system/tests/modules/bundle_test/lib/Drupal/bundle_test/TestFileUsage.php
+++ b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestFileUsage.php
@@ -2,12 +2,13 @@
/**
* @file
- * Definition of Drupal\bundle_test\TestFileUsage.
+ * Definition of Drupal\service_provider_test\TestFileUsage.
*/
-namespace Drupal\bundle_test;
+namespace Drupal\service_provider_test;
use Drupal\file\Plugin\Core\Entity\File;
+use Drupal\file\FileUsage\FileUsageBase;
class TestFileUsage extends FileUsageBase {
diff --git a/core/modules/system/tests/modules/service_provider_test/service_provider_test.info.yml b/core/modules/system/tests/modules/service_provider_test/service_provider_test.info.yml
new file mode 100644
index 0000000..620c897
--- /dev/null
+++ b/core/modules/system/tests/modules/service_provider_test/service_provider_test.info.yml
@@ -0,0 +1,7 @@
+name: 'Service Provider test'
+type: module
+description: 'Support module for service provider testing.'
+package: Testing
+version: VERSION
+core: 8.x
+hidden: true
diff --git a/core/modules/system/tests/modules/bundle_test/bundle_test.module b/core/modules/system/tests/modules/service_provider_test/service_provider_test.module
index b3d9bbc..b3d9bbc 100644
--- a/core/modules/system/tests/modules/bundle_test/bundle_test.module
+++ b/core/modules/system/tests/modules/service_provider_test/service_provider_test.module
diff --git a/core/modules/system/tests/modules/service_provider_test/service_provider_test.services.yml b/core/modules/system/tests/modules/service_provider_test/service_provider_test.services.yml
new file mode 100644
index 0000000..dda70f5
--- /dev/null
+++ b/core/modules/system/tests/modules/service_provider_test/service_provider_test.services.yml
@@ -0,0 +1,7 @@
+services:
+ service_provider_test_class:
+ class: Drupal\service_provider_test\TestClass
+ tags:
+ - { name: event_subscriber }
+ - { name: needs_destruction }
+ arguments: ['@state']
diff --git a/core/update.php b/core/update.php
index b73e3ce..3b6afe3 100644
--- a/core/update.php
+++ b/core/update.php
@@ -186,7 +186,7 @@ function update_helpful_links() {
* while updates are running.
*/
function update_flush_all_caches() {
- unset($GLOBALS['conf']['container_bundles']['UpdateBundle']);
+ unset($GLOBALS['conf']['container_service_providers']['UpdateServiceProvider']);
Drupal::service('kernel')->updateModules(Drupal::moduleHandler()->getModuleList());
// No updates to run, so caches won't get flushed later. Clear them now.