Skip to content

Commit eb0945f

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [DependencyInjection] Fix "proxy" tag: resolve its parameters and pass it to child definitions Complete negatable options
2 parents a56daa8 + beecae1 commit eb0945f

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
@@ -189,6 +189,12 @@ private function doResolveDefinition(ChildDefinition $definition): Definition
189189
// and it's not legal on an instanceof
190190
$def->setAutoconfigured($definition->isAutoconfigured());
191191

192+
if (!$def->hasTag('proxy')) {
193+
foreach ($parentDef->getTag('proxy') as $v) {
194+
$def->addTag('proxy', $v);
195+
}
196+
}
197+
192198
return $def;
193199
}
194200
}

Compiler/ResolveParameterPlaceHoldersPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
8383
if (isset($changes['file'])) {
8484
$value->setFile($this->bag->resolveValue($value->getFile()));
8585
}
86+
$tags = $value->getTags();
87+
if (isset($tags['proxy'])) {
88+
$tags['proxy'] = $this->bag->resolveValue($tags['proxy']);
89+
$value->setTags($tags);
90+
}
8691
}
8792

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

Tests/Compiler/ResolveChildDefinitionsPassTest.php

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

121+
public function testProcessCopiesTagsProxy()
122+
{
123+
$container = new ContainerBuilder();
124+
125+
$container
126+
->register('parent')
127+
->addTag('proxy', ['a' => 'b'])
128+
;
129+
130+
$container
131+
->setDefinition('child1', new ChildDefinition('parent'))
132+
;
133+
$container
134+
->setDefinition('child2', (new ChildDefinition('parent'))->addTag('proxy', ['c' => 'd']))
135+
;
136+
137+
$this->process($container);
138+
139+
$def = $container->getDefinition('child1');
140+
$this->assertSame(['proxy' => [['a' => 'b']]], $def->getTags());
141+
142+
$def = $container->getDefinition('child2');
143+
$this->assertSame(['proxy' => [['c' => 'd']]], $def->getTags());
144+
}
145+
121146
public function testProcessDoesNotCopyDecoratedService()
122147
{
123148
$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)