diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php index 5fdbe5686dbfa..72b093043bf15 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php @@ -39,6 +39,10 @@ protected function processValue($value, $isRoot = false) return self::register($this->container, $value->getValues()); } + if ($value instanceof Definition) { + $value->setBindings(parent::processValue($value->getBindings())); + } + if (!$value instanceof Definition || !$value->hasTag('container.service_locator')) { return parent::processValue($value, $isRoot); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php index 25063d35ff3b5..bf6428ee2de47 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\BoundArgument; +use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; @@ -143,4 +144,16 @@ public function testBindingsAreCopied() $this->assertSame(['foo'], array_keys($locator->getBindings())); $this->assertInstanceOf(BoundArgument::class, $locator->getBindings()['foo']); } + + public function testBindingsAreProcessed() + { + $container = new ContainerBuilder(); + + $definition = $container->register('foo') + ->setBindings(['foo' => new ServiceLocatorArgument()]); + + (new ServiceLocatorTagPass())->process($container); + + $this->assertInstanceOf(Reference::class, $definition->getBindings()['foo']->getValues()[0]); + } }