8000 bug #48224 [DependencyInjection] Process bindings in `ServiceLocatorT… · symfony/symfony@0f670bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f670bb

Browse files
committed
bug #48224 [DependencyInjection] Process bindings in ServiceLocatorTagPass (MatTheCat)
This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Process bindings in `ServiceLocatorTagPass` | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48192 | License | MIT | Doc PR | N/A Commits ------- 81d0858 [DependencyInjection] Process bindings in ServiceLocatorTagPass
2 parents 0eebba6 + 81d0858 commit 0f670bb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ protected function processValue($value, $isRoot = false)
3939
return self::register($this->container, $value->getValues());
4040
}
4141

42+
if ($value instanceof Definition) {
43+
$value->setBindings(parent::processValue($value->getBindings()));
44+
}
45+
4246
if (!$value instanceof Definition || !$value->hasTag('container.service_locator')) {
4347
return parent::processValue($value, $isRoot);
4448
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
16+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1617
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -143,4 +144,16 @@ public function testBindingsAreCopied()
143144
$this->assertSame(['foo'], array_keys($locator->getBindings()));
144145
$this->assertInstanceOf(BoundArgument::class, $locator->getBindings()['foo']);
145146
}
147+
148+
public function testBindingsAreProcessed()
149+
{
150+
$container = new ContainerBuilder();
151+
152+
$definition = $container->register('foo')
153+
->setBindings(['foo' => new ServiceLocatorArgument()]);
154+
155+
(new ServiceLocatorTagPass())->process($container);
156+
157+
$this->assertInstanceOf(Reference::class, $definition->getBindings()['foo']->getValues()[0]);
158+
}
146159
}

0 commit comments

Comments
 (0)
0