Skip to content

Commit 97f0ce8

Browse files
bug symfony#48483 [DependencyInjection] Remove refs that point to container.excluded services when allowed (nicolas-grekas)
This PR was merged into the 6.2 branch. Discussion ---------- [DependencyInjection] Remove refs that point to container.excluded services when allowed | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#48411 | License | MIT | Doc PR | - Commits ------- 2e9fdf0 [DependencyInjection] Remove refs that point to container.excluded services when allowed
2 parents 79e1d8d + 2e9fdf0 commit 97f0ce8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private function processValue(mixed $value, int $rootLevel = 0, int $level = 0):
9595
$value = array_values($value);
9696
}
9797
} elseif ($value instanceof Reference) {
98-
if ($this->container->has($id = (string) $value)) {
98+
if ($this->container->hasDefinition($id = (string) $value) ? !$this->container->getDefinition($id)->hasTag('container.excluded') : $this->container->hasAlias($id)) {
9999
return $value;
100100
}
101101

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInvalidReferencesPassTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ public function testProcessSetOnlyDecoratedAsNullOnInvalid()
165165
$this->assertEquals($unknownArgument, $decoratorDefinition->getArguments()[1]);
166166
}
167167

168+
public function testProcessExcludedServiceAndNullOnInvalid()
169+
{
170+
$container = new ContainerBuilder();
171+
$container->register('foo', \stdClass::class)->addTag('container.excluded');
172+
$container->register('bar', \stdClass::class)->addArgument(new Reference('foo', $container::NULL_ON_INVALID_REFERENCE));
173+
174+
$this->process($container);
175+
176+
$this->assertSame([null], $container->getDefinition('bar')->getArguments());
177+
}
178+
168179
protected function process(ContainerBuilder $container)
169180
{
170181
$pass = new ResolveInvalidReferencesPass();

0 commit comments

Comments
 (0)