[DI] [FrameworkBundle] Add LoggerAwareInterface to auto configuration
This commit is contained in:
parent
00e8b493d1
commit
afda3c8844
|
@ -8,6 +8,7 @@ CHANGELOG
|
||||||
* Allowed configuring PDO-based cache pools via a new `cache.adapter.pdo` abstract service
|
* 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 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.
|
* 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
|
4.1.0
|
||||||
-----
|
-----
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
|
||||||
|
|
||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||||
use Doctrine\Common\Annotations\Reader;
|
use Doctrine\Common\Annotations\Reader;
|
||||||
|
use Psr\Log\LoggerAwareInterface;
|
||||||
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
|
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
|
||||||
use Symfony\Bridge\Monolog\Processor\ProcessorInterface;
|
use Symfony\Bridge\Monolog\Processor\ProcessorInterface;
|
||||||
use Symfony\Bridge\Twig\Extension\CsrfExtension;
|
use Symfony\Bridge\Twig\Extension\CsrfExtension;
|
||||||
|
@ -360,6 +361,8 @@ class FrameworkExtension extends Extension
|
||||||
->addTag('messenger.message_handler');
|
->addTag('messenger.message_handler');
|
||||||
$container->registerForAutoconfiguration(TransportFactoryInterface::class)
|
$container->registerForAutoconfiguration(TransportFactoryInterface::class)
|
||||||
->addTag('messenger.transport_factory');
|
->addTag('messenger.transport_factory');
|
||||||
|
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
|
||||||
|
->addMethodCall('setLogger', array(new Reference('logger')));
|
||||||
|
|
||||||
if (!$container->getParameter('kernel.debug')) {
|
if (!$container->getParameter('kernel.debug')) {
|
||||||
// remove tagged iterator argument for resource checkers
|
// remove tagged iterator argument for resource checkers
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
|
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
|
||||||
|
|
||||||
use Doctrine\Common\Annotations\Annotation;
|
use Doctrine\Common\Annotations\Annotation;
|
||||||
|
use Psr\Log\LoggerAwareInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
|
||||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
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\Cache\Adapter\RedisAdapter;
|
||||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
@ -1224,6 +1226,22 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||||
$this->assertEmpty($container->getDefinition('config_cache_factory')->getArguments());
|
$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())
|
protected function createContainer(array $data = array())
|
||||||
{
|
{
|
||||||
return new ContainerBuilder(new ParameterBag(array_merge(array(
|
return new ContainerBuilder(new ParameterBag(array_merge(array(
|
||||||
|
|
Reference in New Issue