Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DependencyInjection] Process bindings in ServiceLocatorTagPass #48224

Merged
merged 1 commit into from Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
}