Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit de33b25

Browse filesBrowse files
committed
[DependencyInjection] Process bindings in ServiceLocatorTagPass
1 parent 0eebba6 commit de33b25
Copy full SHA for de33b25

File tree

2 files changed

+17
-0
lines changed
Filter options

2 files changed

+17
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php
+4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php
+13Lines 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 testBindingsAreRegistered()
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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.