Skip to content

Commit fc1fcd2

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

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

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

Compiler/ResolveParameterPlaceHoldersPass.php

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

8994
$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)