diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php index 5c04a32..310343e 100644 --- a/core/lib/Drupal/Core/CoreServiceProvider.php +++ b/core/lib/Drupal/Core/CoreServiceProvider.php @@ -74,13 +74,6 @@ public function register(ContainerBuilder $container) { } /** - * {@inheritdoc} - */ - public function alter(ContainerBuilder $container) { - - } - - /** * Registers the module handler. * * As this is different during install, it needs to stay in PHP. diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php index a00cc25..25614e3 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php @@ -7,6 +7,8 @@ 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; @@ -23,12 +25,14 @@ public function process(ContainerBuilder $container) { return; } $kernel = $container->get('kernel'); - if (!is_a($kernel, 'Drupal\Core\DrupalKernel')) { + if (!($kernel instanceof DrupalKernelInterface)) { return; } $providers = $kernel->getServiceProviders(); foreach ($providers as $provider) { - $provider->alter($container); + 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 @@ +register('router.builder', 'Drupal\Core\Routing\RouteBuilderStatic'); } - public function alter(ContainerBuilder $container) { - - } - } 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 index e177a46..c8b1633 100644 --- 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 @@ -8,12 +8,13 @@ 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 { +class LanguageTestServiceProvider implements ServiceProviderInterface, ServiceModifierInterface { /** * {@inheritdoc} diff --git a/core/modules/serialization/lib/Drupal/serialization/SerializationServiceProvider.php b/core/modules/serialization/lib/Drupal/serialization/SerializationServiceProvider.php index 8fc239d..2e89e5c 100644 --- a/core/modules/serialization/lib/Drupal/serialization/SerializationServiceProvider.php +++ b/core/modules/serialization/lib/Drupal/serialization/SerializationServiceProvider.php @@ -24,11 +24,4 @@ public function register(ContainerBuilder $container) { // Add a compiler pass for adding concrete Resolvers to chain Resolver. $container->addCompilerPass(new RegisterEntityResolversCompilerPass()); } - - /** - * {@inheritdoc} - */ - public function alter(ContainerBuilder $container) { - - } } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestServiceProvider.php b/core/modules/simpletest/lib/Drupal/simpletest/TestServiceProvider.php index cdc07b4..9b26f12 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestServiceProvider.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestServiceProvider.php @@ -20,12 +20,4 @@ function register(ContainerBuilder $container) { static::$currentTest->containerBuild($container); } } - - /** - * {@inheritdoc} - */ - function alter(ContainerBuilder $container) { - - } - } diff --git a/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php b/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php index 12791a2..bffd0f0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/ServiceProvider/ServiceProviderTest.php @@ -2,37 +2,37 @@ /** * @file - * Definition of Drupal\system\Tests\Bundle\BundleTest. + * Definition of Drupal\system\Tests\ServiceProvider\ServiceProviderTest. */ -namespace Drupal\system\Tests\Bundle; +namespace Drupal\system\Tests\ServiceProvider; use Drupal\simpletest\WebTestBase; /** - * Tests bundle registration to the DIC. + * Tests service provider registration to the DIC. */ -class BundleTest extends WebTestBase { +class ServiceProviderTest extends WebTestBase { /** * Modules to enable. * * @var array */ - public static $modules = array('service_provider_test'); + public static $modules = array('file', 'service_provider_test'); public static function getInfo() { return array( - 'name' => 'Bundle Registration', - 'description' => 'Tests bundle registration to the DIC.', - 'group' => 'Bundle', + 'name' => 'Service Provider Registration', + 'description' => 'Tests service provider registration to the DIC.', + 'group' => 'Service Provider', ); } /** - * Tests that services provided by module bundles get registered to the DIC. + * Tests that services provided by module service providers get registered to the DIC. */ - function testBundleRegistration() { + 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 @@ -45,12 +45,12 @@ function testBundleRegistration() { /** * 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. + 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 bundle's service is registered. + // 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/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php b/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php index 69062db..9c1dbc3 100644 --- a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php +++ b/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/RouterTestServiceProvider.php @@ -23,11 +23,4 @@ public function register(ContainerBuilder $container) { $container->register('access_check.router_test', 'Drupal\router_test\Access\TestAccessCheck') ->addTag('access_check'); } - - /** - * {@inheritdoc} - */ - public function alter(ContainerBuilder $container) { - - } } 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 @@ +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/service_provider_test/lib/Drupal/service_provider_test/TestFileUsage.php b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestFileUsage.php index df6cb44..93919dc 100644 --- a/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestFileUsage.php +++ b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestFileUsage.php @@ -8,6 +8,7 @@ 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.services.yml b/core/modules/system/tests/modules/service_provider_test/service_provider_test.services.yml index 4c75baf..dda70f5 100644 --- 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 @@ -5,5 +5,3 @@ services: - { name: event_subscriber } - { name: needs_destruction } arguments: ['@state'] - file.usage: - class: Drupal\service_provider_test\TestFileUsage