diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 9db617520d8d..744645dd7018 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -52,14 +52,14 @@ public function __construct() new ValidateEnvPlaceholdersPass(), new ResolveChildDefinitionsPass(), new RegisterServiceSubscribersPass(), - new DecoratorServicePass(), new ResolveParameterPlaceHoldersPass(false), - new ResolveFactoryClassPass(), new ResolveNamedArgumentsPass(), - new AutowireRequiredMethodsPass(), new ResolveBindingsPass(), new ServiceLocatorTagPass(), new CheckDefinitionValidityPass(), + new DecoratorServicePass(), + new ResolveFactoryClassPass(), + new AutowireRequiredMethodsPass(), new AutowirePass(false), new ResolveTaggedIteratorArgumentPass(), new ResolveServiceSubscribersPass(), diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php index fc300fde21c1..1865dd6772f0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php @@ -24,6 +24,7 @@ use Symfony\Component\DependencyInjection\Tests\Fixtures\BarTagClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\FooBarTaggedClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass; +use Symfony\Contracts\Service\ServiceProviderInterface; /** * This class tests the integration of the different compiler passes. @@ -142,6 +143,29 @@ public function testCanDecorateServiceSubscriber() $this->assertInstanceOf(DecoratedServiceSubscriber::class, $container->get(ServiceSubscriberStub::class)); } + public function testCanDecorateServiceLocator() + { + $container = new ContainerBuilder(); + + $container->register('foo', 'stdClass')->setPublic(true); + + $container->register(ServiceLocator::class) + ->addTag('container.service_locator') + ->setArguments([[new Reference('foo')]]) + ; + + $container->register(DecoratedServiceLocator::class) + ->setDecoratedService(ServiceLocator::class) + ->setPublic(true) + ->setArguments([new Reference(DecoratedServiceLocator::class.'.inner')]) + ; + + $container->compile(); + + $this->assertInstanceOf(DecoratedServiceLocator::class, $container->get(DecoratedServiceLocator::class)); + $this->assertSame($container->get('foo'), $container->get(DecoratedServiceLocator::class)->get('foo')); + } + /** * @dataProvider getYamlCompileTests */ @@ -416,6 +440,34 @@ class DecoratedServiceSubscriber { } +class DecoratedServiceLocator implements ServiceProviderInterface +{ + /** + * @var ServiceLocator + */ + private $locator; + + public function __construct(ServiceLocator $locator) + { + $this->locator = $locator; + } + + public function get($id) + { + return $this->locator->get($id); + } + + public function has($id): bool + { + return $this->locator->has($id); + } + + public function getProvidedServices(): array + { + return $this->locator->getProvidedServices(); + } +} + class IntegrationTestStub extends IntegrationTestStubParent { }