Skip to content

Commit

Permalink
[DependencyInjection] Process bindings in ServiceLocatorTagPass
Browse files Browse the repository at this point in the history
  • Loading branch information
MatTheCat committed Nov 16, 2022
1 parent 0eebba6 commit de33b25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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 testBindingsAreRegistered()
{
$container = new ContainerBuilder();

$definition = $container->register('foo')
->setBindings(['foo' => new ServiceLocatorArgument()]);

(new ServiceLocatorTagPass())->process($container);

$this->assertInstanceOf(Reference::class, $definition->getBindings()['foo']->getValues()[0]);
}
}

0 comments on commit de33b25

Please sign in to comment.