8000 bug #59357 [HttpKernel] Don't override existing `LoggerInterface` aut… · symfony/symfony@dd50db5 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd50db5

Browse files
committed
bug #59357 [HttpKernel] Don't override existing LoggerInterface autowiring alias in LoggerPass (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [HttpKernel] Don't override existing `LoggerInterface` autowiring alias in `LoggerPass` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Something we missed in #24300 Explicit configuration should always have highest precedence, yet LoggerPass ignores the existing autowiring alias at the moment. Commits ------- 771a79d [HttpKernel] Don't override existing LoggerInterface autowiring alias in LoggerPass
2 parents 4166af2 + 771a79d commit dd50db5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/HttpKernel/DependencyInjection/LoggerPass.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class LoggerPass implements CompilerPassInterface
3030
*/
3131
public function process(ContainerBuilder $container)
3232
{
33-
$container->setAlias(LoggerInterface::class, 'logger');
33+
if (!$container->has(LoggerInterface::class)) {
34+
$container->setAlias(LoggerInterface::class, 'logger');
35+
}
3436

3537
if ($container->has('logger')) {
3638
return;

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/LoggerPassTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,15 @@ public function testRegisterLogger()
5353
$this->assertSame(Logger::class, $definition->getClass());
5454
$this->assertFalse($definition->isPublic());
5555
}
56+
57+
public function testAutowiringAliasIsPreserved()
58+
{
59+
$container = new ContainerBuilder();
60+
$container->setParameter('kernel.debug', false);
61+
$container->setAlias(LoggerInterface::class, 'my_logger');
62+
63+
(new LoggerPass())->process($container);
64+
65+
$this->assertSame('my_logger', (string) $container->getAlias(LoggerInterface::class));
66+
}
5667
}

0 commit comments

Comments
 (0)
0