diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index e285ebf8a1..79f3c47567 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * Allowed configuring PDO-based cache pools via a new `cache.adapter.pdo` abstract service * Deprecated auto-injection of the container in AbstractController instances, register them as service subscribers instead * Deprecated processing of services tagged `security.expression_language_provider` in favor of a new `AddExpressionLanguageProvidersPass` in SecurityBundle. + * Enabled autoconfiguration for `Psr\Log\LoggerAwareInterface` 4.1.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 736e98e306..5f27479509 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection; use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\Reader; +use Psr\Log\LoggerAwareInterface; use Symfony\Bridge\Monolog\Processor\DebugProcessor; use Symfony\Bridge\Monolog\Processor\ProcessorInterface; use Symfony\Bridge\Twig\Extension\CsrfExtension; @@ -360,6 +361,8 @@ class FrameworkExtension extends Extension ->addTag('messenger.message_handler'); $container->registerForAutoconfiguration(TransportFactoryInterface::class) ->addTag('messenger.transport_factory'); + $container->registerForAutoconfiguration(LoggerAwareInterface::class) + ->addMethodCall('setLogger', array(new Reference('logger'))); if (!$container->getParameter('kernel.debug')) { // remove tagged iterator argument for resource checkers diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 69d5647e2f..526816797d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; use Doctrine\Common\Annotations\Annotation; +use Psr\Log\LoggerAwareInterface; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; @@ -26,6 +27,7 @@ use Symfony\Component\Cache\Adapter\ProxyAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; @@ -1224,6 +1226,22 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertEmpty($container->getDefinition('config_cache_factory')->getArguments()); } + public function testLoggerAwareRegistration() + { + $container = $this->createContainerFromFile('full', array(), true, false); + $container->addCompilerPass(new ResolveInstanceofConditionalsPass()); + $container->register('foo', LoggerAwareInterface::class) + ->setAutoconfigured(true); + $container->compile(); + + $calls = $container->findDefinition('foo')->getMethodCalls(); + + $this->assertCount(1, $calls, 'Definition should contain 1 method call'); + $this->assertSame('setLogger', $calls[0][0], 'Method name should be "setLogger"'); + $this->assertInstanceOf(Reference::class, $calls[0][1][0]); + $this->assertSame('logger', (string) $calls[0][1][0], 'Argument should be a reference to "logger"'); + } + protected function createContainer(array $data = array()) { return new ContainerBuilder(new ParameterBag(array_merge(array(