Skip to content

Commit beecae1

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: [DependencyInjection] Fix "proxy" tag: resolve its parameters and pass it to child definitions
2 parents 0f40c43 + f6fdbf2 commit beecae1

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

Compiler/ResolveChildDefinitionsPass.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ private function doResolveDefinition(ChildDefinition $definition): Definition
193193
// and it's not legal on an instanceof
194194
$def->setAutoconfigured($definition->isAutoconfigured());
195195

196+
if (!$def->hasTag('proxy')) {
197+
foreach ($parentDef->getTag('proxy') as $v) {
198+
$def->addTag('proxy', $v);
199+
}
200+
}
201+
196202
return $def;
197203
}
198204
}

Compiler/ResolveParameterPlaceHoldersPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ protected function processValue($value, bool $isRoot = false)
8585
if (isset($changes['file'])) {
8686
$value->setFile($this->bag->resolveValue($value->getFile()));
8787
}
88+
$tags = $value->getTags();
89+
if (isset($tags['proxy'])) {
90+
$tags['proxy'] = $this->bag->resolveValue($tags['proxy']);
91+
$value->setTags($tags);
92+
}
8893
}
8994

9095
$value = parent::processValue($value, $isRoot);

Tests/Compiler/ResolveChildDefinitionsPassTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,31 @@ public function testProcessDoesNotCopyTags()
121121
$this->assertEquals([], $def->getTags());
122122
}
123123

124+
public function testProcessCopiesTagsProxy()
125+
{
126+
$container = new ContainerBuilder();
127+
128+
$container
129+
->register('parent')
130+
->addTag('proxy', ['a' => 'b'])
131+
;
132+
133+
$container
134+
->setDefinition('child1', new ChildDefinition('parent'))
135+
;
136+
$container
137+
->setDefinition('child2', (new ChildDefinition('parent'))->addTag('proxy', ['c' => 'd']))
138+
;
139+
140+
$this->process($container);
141+
142+
$def = $container->getDefinition('child1');
143+
$this->assertSame(['proxy' => [['a' => 'b']]], $def->getTags());
144+
145+
$def = $container->getDefinition('child2');
146+
$this->assertSame(['proxy' => [['c' => 'd']]], $def->getTags());
147+
}
148+
124149
public function testProcessDoesNotCopyDecoratedService()
125150
{
126151
$container = new ContainerBuilder();

Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ public function testParameterNotFoundExceptionsIsNotThrown()
9797
$this->assertCount(1, $definition->getErrors());
9898
}
9999

100+
public function testOnlyProxyTagIsResolved()
101+
{
102+
$containerBuilder = new ContainerBuilder();
103+
$containerBuilder->setParameter('a_param', 'here_you_go');
104+
$definition = $containerBuilder->register('def');
105+
$definition->addTag('foo', ['bar' => '%a_param%']);
106+
$definition->addTag('proxy', ['interface' => '%a_param%']);
107+
108+
$pass = new ResolveParameterPlaceHoldersPass(true, false);
109+
$pass->process($containerBuilder);
110+
111+
$this->assertSame(['foo' => [['bar' => '%a_param%']], 'proxy' => [['interface' => 'here_you_go']]], $definition->getTags());
112+
}
113+
100114
private function createContainerBuilder(): ContainerBuilder
101115
{
102116
$containerBuilder = new ContainerBuilder();

0 commit comments

Comments
 (0)