diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index cf0e3ddea34505899a0353e9757c42245df32b3c..a818c78d69786a076be98b04f4d3f9c565628fbc 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 77771d86f44eb573ed084e9eb5c5a3e042316200..34936d003d0269b72701c794864c4415a2164921 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -4,14 +4,14 @@ 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 b0ca2961f62118fbc20fa818d231eb80b9d088be..e0e86cce1d40a11eddb92b1945104eb5a6f5398d 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 3659caf178abc3193694c4042cf09a57cda04611..fe83e317a442bf3086d3e4be5ad9512ccec2fd00 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 bb4368ca268ccd02ab5eb447ff93c43ebb7d1375..1fa80fc0f525b895c0064760b6c7b0ae656f9d20 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -19,8 +19,8 @@ * * 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 similarity index 90% rename from core/lib/Drupal/Core/CoreBundle.php rename to core/lib/Drupal/Core/CoreServiceProvider.php index 9af0c74400d65eb6626b8a1bc6d42e1ce445d3ed..310343e280d60c04f6bf254ac789f5ffa1ee54eb 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\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 @@ * 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 @@ public function build(ContainerBuilder $container) { // 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 0000000000000000000000000000000000000000..25614e351bb1732c4731c422ba439615c0fa90f8 --- /dev/null +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php @@ -0,0 +1,39 @@ +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 0000000000000000000000000000000000000000..000366c56e80748afc8adedcc30f8691d42a68ea --- /dev/null +++ b/core/lib/Drupal/Core/DependencyInjection/ServiceModifierInterface.php @@ -0,0 +1,18 @@ +register('lock', 'Drupal\Core\Lock\NullLockBackend'); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 6d7d4faebe8af60e40134571b440248e8724eea8..af1fe523c5e3471e280dd36fd07a08cfc290b715 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -9,26 +9,55 @@ 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. @@ -107,6 +136,13 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface { */ protected $serviceYamls; + /** + * The array of registered service providers. + * + * @var array + */ + protected $serviceProviders; + /** * Constructs a DrupalKernel object. * @@ -114,21 +150,18 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface { * 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 @@ public function __construct($environment, $debug, ClassLoader $class_loader, $al * {@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 @@ public function boot() { } $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 @@ public function registerBundles() { $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 @@ public function registerBundles() { } } - // 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 @@ public function updateModules(array $module_list, array $module_filenames = arra } // 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 @@ public function updateModules(array $module_list, array $module_filenames = arra } /** - * 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 @@ protected function getClassName() { 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 @@ protected function initializeContainer() { } $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 @@ protected function persistServices(array $persist) { * @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 @@ protected function buildContainer() { 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 @@ -463,6 +548,22 @@ protected function buildContainer() { return $container; } + /** + * 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. * @@ -497,6 +598,16 @@ protected function dumpDrupalContainer(ContainerBuilder $container, $baseClass) 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 60d0403020fcbb6de743767b7d76b2b004d98e2d..96b2f922ea12975a71d614c116d324c342f857ee 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 @@ * 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 656e918ac87e72e84261f478652d2dbfefaa81e0..c5101927df3f4fd1a5ec2043bdade89af70877a1 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 898fdf8280b63904e5f2080572f285b9808ea1f0..3c86bd1146ff6c0b3ae9188c98d5a78f54537a57 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 @@ /** * 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 b7115073bdc7be49b63191a5c388fd02b5676c86..0000000000000000000000000000000000000000 --- a/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestBundle.php +++ /dev/null @@ -1,28 +0,0 @@ -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 0000000000000000000000000000000000000000..c8b16330327e4c1c37da695e8eb55d6e409dec65 --- /dev/null +++ b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestServiceProvider.php @@ -0,0 +1,36 @@ +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 similarity index 57% rename from core/modules/serialization/lib/Drupal/serialization/SerializationBundle.php rename to core/modules/serialization/lib/Drupal/serialization/SerializationServiceProvider.php index f649052ef05634bcf049bd230d684e2c26854b57..2e89e5c42a8d1ce95356685165fc54cbc1b6864e 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 2c80dcd8d5020a0afed884578902097a46247ac9..e54e1212aad5f1366f8bcc96725748ee50b8cc5b 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -90,7 +90,7 @@ protected function setUp() { // 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 @@ protected function setUp() { // 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 1b746e612ab997e837362d7cf9e9d80d67903c8d..818b7b0950dad19b64f832d3354a55b42fc512ad 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -698,7 +698,7 @@ protected function verbose($message) { * 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 @@ public function run(array $methods = array()) { } } } - 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 @@ protected function prepareConfigDirectories() { * @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 similarity index 51% rename from core/modules/simpletest/lib/Drupal/simpletest/TestBundle.php rename to core/modules/simpletest/lib/Drupal/simpletest/TestServiceProvider.php index 7e2fd2f8d9677d21a82e539135697107b8360063..9b26f12c5f99b886516aa40b7371a9944826066b 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 fb165a47da97e4d46020019ce81dd7bd198c19dc..7f4b0c2299c74927d9a1501e9c763280961b2e72 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 35faa3c4280ca922cec88444a26ff1e8870467e6..0000000000000000000000000000000000000000 --- a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php +++ /dev/null @@ -1,58 +0,0 @@ - '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 87c70191f97de6cab2a1e362e77c6af3db2c6306..db60d18296f4eeefae57922f30569e5038f8573d 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 @@ function testCompileDIC() { '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 @@ function testCompileDIC() { // 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 @@ function testCompileDIC() { // 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 @@ function testCompileDIC() { $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 @@ function testCompileDIC() { */ 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 9bfde63cd70b183350fd9765a207aca35a03e4dc..a48e8836512eff1e2196c6a38c758a5a4a78ed3a 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 @@ public static function getInfo() { */ 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 @@ public function testDestructionUsed() { */ 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 0000000000000000000000000000000000000000..bffd0f011dc7978433a5c6200d3a0e55e3e601c3 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php @@ -0,0 +1,58 @@ + '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 bf004f9444acd19df469ee7de4e92318e641bc5b..da653779e5029ce0fc229e4c58ac71aa9b0185f7 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 @@ function testSystemInitIgnoresSlaves() { 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 b613121d8884d7ca996c7d63a76b5d1cc0c28c5a..8a1cb683b785b7a9cacd53de892576915ab8dfc8 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 @@ protected function setUp() { // 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 49335fb9b4637274b6322f7fe73b26c2fe932ff8..0000000000000000000000000000000000000000 --- 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 88b3caf5a78415e650fd69e471fae4eade720fbe..0000000000000000000000000000000000000000 --- 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 similarity index 53% rename from core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestBundle.php rename to core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php index 114ddf4fd8ed8260897b01e269fd9ccc25797186..9c1dbc3a772e249764a2ee8ca3c2ce33715a3518 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 0000000000000000000000000000000000000000..b2b85cbd75bced60ab3a821ccee05a014ba8c616 --- /dev/null +++ b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/ServiceProviderTestServiceProvider.php @@ -0,0 +1,33 @@ +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 similarity index 83% rename from core/modules/system/tests/modules/bundle_test/lib/Drupal/bundle_test/TestClass.php rename to core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestClass.php index ad711cbb9db848ee1a97a0110626a74ca270b368..1c8ea06caf7c6403193d9b89b1a0a513beb13470 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 @@ public function __construct(KeyValueStoreInterface $state) { * 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 @@ static function getSubscribedEvents() { * 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 similarity index 79% rename from core/modules/system/tests/modules/bundle_test/lib/Drupal/bundle_test/TestFileUsage.php rename to core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestFileUsage.php index 0ee5f2d344ae15ea878dacfd17fa847b5ca6e545..93919dcae89568c38041a03a41c7e9a30ec73260 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 0000000000000000000000000000000000000000..620c8972a613fb2b7dcc8118c9195899f602f573 --- /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 similarity index 100% rename from core/modules/system/tests/modules/bundle_test/bundle_test.module rename to 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 0000000000000000000000000000000000000000..dda70f5996221f5bc1f8805b5046620462eb70be --- /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 b73e3ce26e9ecf87116ab1a1cec8fb05f578cccc..3b6afe35c6ca94f6ed02565ef00426c750dd111a 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.