From a32cae5caaebff52872c9a5e8d375a7dd35d5104 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Mon, 3 Jul 2017 19:07:33 +0200 Subject: [PATCH] [FrameworkBundle] Wire inner translator --- .../Compiler/LoggingTranslatorPass.php | 12 ++++++++++-- .../Compiler/LoggingTranslatorPassTest.php | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php index 7d47dd2f9b..ed0e811e0a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php @@ -14,7 +14,6 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; -use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorBagInterface; @@ -39,7 +38,16 @@ class LoggingTranslatorPass implements CompilerPassInterface } if ($r->isSubclassOf(TranslatorInterface::class) && $r->isSubclassOf(TranslatorBagInterface::class)) { $container->getDefinition('translator.logging')->setDecoratedService('translator'); - $container->getDefinition('translation.warmer')->replaceArgument(0, new Reference('translator.logging.inner')); + $warmer = $container->getDefinition('translation.warmer'); + $subscriberAttributes = $warmer->getTag('container.service_subscriber'); + $warmer->clearTag('container.service_subscriber'); + + foreach ($subscriberAttributes as $k => $v) { + if ((!isset($v['id']) || 'translator' !== $v['id']) && (!isset($v['key']) || 'translator' !== $v['key'])) { + $warmer->addTag('container.service_subscriber', $v); + } + } + $warmer->addTag('container.service_subscriber', array('key' => 'translator', 'id' => 'translator.logging.inner')); } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php index eda507c621..a93d8ca5d0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php @@ -60,6 +60,22 @@ class LoggingTranslatorPassTest extends TestCase ->with('Symfony\Bundle\FrameworkBundle\Translation\Translator') ->will($this->returnValue(new \ReflectionClass('Symfony\Bundle\FrameworkBundle\Translation\Translator'))); + $definition->expects($this->once()) + ->method('getTag') + ->with('container.service_subscriber') + ->willReturn(array(array('id' => 'translator'), array('id' => 'foo'))); + + $definition->expects($this->once()) + ->method('clearTag') + ->with('container.service_subscriber'); + + $definition->expects($this->any()) + ->method('addTag') + ->withConsecutive( + array('container.service_subscriber', array('id' => 'foo')), + array('container.service_subscriber', array('key' => 'translator', 'id' => 'translator.logging.inner')) + ); + $pass = new LoggingTranslatorPass(); $pass->process($container); }