Skip to content

Commit

Permalink
bug #268 Fix the autowiring of the channel logger in autoconfigured s…
Browse files Browse the repository at this point in the history
…ervices (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
  • Loading branch information
fabpot committed May 29, 2018
2 parents 732424e + b39e571 commit 42abba5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/LoggerChannelPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function process(ContainerBuilder $container)
}
$definition->setMethodCalls($calls);

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

// Mark the binding as used already, to avoid reporting it as unused if the service does not use a
Expand Down
22 changes: 22 additions & 0 deletions Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ public function testAutowiredLoggerArgumentsAreReplacedWithChannelLogger()
$this->assertEquals('monolog.logger.test', (string) $dummyService->getArgument(0));
}

public function testAutowiredLoggerArgumentsAreReplacedWithChannelLoggerWhenAutoconfigured()
{
if (!\method_exists('Symfony\Component\DependencyInjection\Definition', 'getBindings')) {
$this->markTestSkipped('Need DependencyInjection 3.4+ to autowire channel logger.');
}

$container = $this->getFunctionalContainer();

$container->registerForAutoconfiguration('Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler\DummyService')
->setProperty('fake', 'dummy');

$container->register('dummy_service', 'Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler\DummyService')
->setAutowired(true)
->setAutoconfigured(true)
->setPublic(true)
->addTag('monolog.logger', array('channel' => 'test'));

$container->compile();

$this->assertEquals('monolog.logger.test', (string) $container->getDefinition('dummy_service')->getArgument(0));
}

public function testAutowiredLoggerArgumentsAreNotReplacedWithChannelLoggerIfLoggerArgumentIsConfiguredExplicitly()
{
if (!\method_exists('Symfony\Component\DependencyInjection\Definition', 'getBindings')) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=5.6",
"symfony/monolog-bridge": "~2.7|~3.3|~4.0",
"symfony/dependency-injection": "~2.7|~3.3|~4.0",
"symfony/dependency-injection": "~2.7|~3.4.10|^4.0.10",
"symfony/config": "~2.7|~3.3|~4.0",
"symfony/http-kernel": "~2.7|~3.3|~4.0",
"monolog/monolog": "~1.22"
Expand Down

0 comments on commit 42abba5

Please sign in to comment.