Skip to content

Commit 42abba5

Browse files
committed
bug #268 Fix the autowiring of the channel logger in autoconfigured services (stof)
This PR was merged into the 3.x-dev branch. Discussion ---------- Fix the autowiring of the channel logger in autoconfigured services This depends on symfony/symfony#27271, hence the new min version of the DI component Commits ------- b39e571 Fix the autowiring of the channel logger in autoconfigured services
2 parents 732424e + b39e571 commit 42abba5

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

DependencyInjection/Compiler/LoggerChannelPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function process(ContainerBuilder $container)
6363
}
6464
$definition->setMethodCalls($calls);
6565

66-
if (!$definition instanceof ChildDefinition && \method_exists($definition, 'getBindings')) {
66+
if (\method_exists($definition, 'getBindings')) {
6767
$binding = new BoundArgument(new Reference($loggerId));
6868

6969
// Mark the binding as used already, to avoid reporting it as unused if the service does not use a

Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,28 @@ public function testAutowiredLoggerArgumentsAreReplacedWithChannelLogger()
8282
$this->assertEquals('monolog.logger.test', (string) $dummyService->getArgument(0));
8383
}
8484

85+
public function testAutowiredLoggerArgumentsAreReplacedWithChannelLoggerWhenAutoconfigured()
86+
{
87+
if (!\method_exists('Symfony\Component\DependencyInjection\Definition', 'getBindings')) {
88+
$this->markTestSkipped('Need DependencyInjection 3.4+ to autowire channel logger.');
89+
}
90+
91+
$container = $this->getFunctionalContainer();
92+
93+
$container->registerForAutoconfiguration('Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler\DummyService')
94+
->setProperty('fake', 'dummy');
95+
96+
$container->register('dummy_service', 'Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler\DummyService')
97+
->setAutowired(true)
98+
->setAutoconfigured(true)
99+
->setPublic(true)
100+
->addTag('monolog.logger', array('channel' => 'test'));
101+
102+
$container->compile();
103+
104+
$this->assertEquals('monolog.logger.test', (string) $container->getDefinition('dummy_service')->getArgument(0));
105+
}
106+
85107
public function testAutowiredLoggerArgumentsAreNotReplacedWithChannelLoggerIfLoggerArgumentIsConfiguredExplicitly()
86108
{
87109
if (!\method_exists('Symfony\Component\DependencyInjection\Definition', 'getBindings')) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=5.6",
2020
"symfony/monolog-bridge": "~2.7|~3.3|~4.0",
21-
"symfony/dependency-injection": "~2.7|~3.3|~4.0",
21+
"symfony/dependency-injection": "~2.7|~3.4.10|^4.0.10",
2222
"symfony/config": "~2.7|~3.3|~4.0",
2323
"symfony/http-kernel": "~2.7|~3.3|~4.0",
2424
"monolog/monolog": "~1.22"

0 commit comments

Comments
 (0)