Skip to content

[DependencyInjection] Fix "proxy" tag: resolve its parameters and pass it to child definitions #46448

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

Merged
merged 1 commit into from
May 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ private function doResolveDefinition(ChildDefinition $definition): Definition
// and it's not legal on an instanceof
$def->setAutoconfigured($definition->isAutoconfigured());

if (!$def->hasTag('proxy')) {
foreach ($parentDef->getTag('proxy') as $v) {
$def->addTag('proxy', $v);
}
}

return $def;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ protected function processValue($value, $isRoot = false)
if (isset($changes['file'])) {
$value->setFile($this->bag->resolveValue($value->getFile()));
}
$tags = $value->getTags();
if (isset($tags['proxy'])) {
$tags['proxy'] = $this->bag->resolveValue($tags['proxy']);
$value->setTags($tags);
}
}

$value = parent::processValue($value, $isRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ public function testProcessDoesNotCopyTags()
$this->assertEquals([], $def->getTags());
}

public function testProcessCopiesTagsProxy()
{
$container = new ContainerBuilder();

$container
->register('parent')
->addTag('proxy', ['a' => 'b'])
;

$container
->setDefinition('child1', new ChildDefinition('parent'))
;
$container
->setDefinition('child2', (new ChildDefinition('parent'))->addTag('proxy', ['c' => 'd']))
;

$this->process($container);

$def = $container->getDefinition('child1');
$this->assertSame(['proxy' => [['a' => 'b']]], $def->getTags());

$def = $container->getDefinition('child2');
$this->assertSame(['proxy' => [['c' => 'd']]], $def->getTags());
}

public function testProcessDoesNotCopyDecoratedService()
{
$container = new ContainerBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ public function testParameterNotFoundExceptionsIsNotThrown()
$this->assertCount(1, $definition->getErrors());
}

public function testOnlyProxyTagIsResolved()
{
$containerBuilder = new ContainerBuilder();
$containerBuilder->setParameter('a_param', 'here_you_go');
$definition = $containerBuilder->register('def');
$definition->addTag('foo', ['bar' => '%a_param%']);
$definition->addTag('proxy', ['interface' => '%a_param%']);

$pass = new ResolveParameterPlaceHoldersPass(true, false);
$pass->process($containerBuilder);

$this->assertSame(['foo' => [['bar' => '%a_param%']], 'proxy' => [['interface' => 'here_you_go']]], $definition->getTags());
}

private function createContainerBuilder(): ContainerBuilder
{
$containerBuilder = new ContainerBuilder();
Expand Down