[FrameworkBundle] Wire inner translator
This commit is contained in:
parent
ddc4b20934
commit
a32cae5caa
@ -14,7 +14,6 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
use Symfony\Component\Translation\TranslatorBagInterface;
|
use Symfony\Component\Translation\TranslatorBagInterface;
|
||||||
|
|
||||||
@ -39,7 +38,16 @@ class LoggingTranslatorPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
if ($r->isSubclassOf(TranslatorInterface::class) && $r->isSubclassOf(TranslatorBagInterface::class)) {
|
if ($r->isSubclassOf(TranslatorInterface::class) && $r->isSubclassOf(TranslatorBagInterface::class)) {
|
||||||
$container->getDefinition('translator.logging')->setDecoratedService('translator');
|
$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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,22 @@ class LoggingTranslatorPassTest extends TestCase
|
|||||||
->with('Symfony\Bundle\FrameworkBundle\Translation\Translator')
|
->with('Symfony\Bundle\FrameworkBundle\Translation\Translator')
|
||||||
->will($this->returnValue(new \ReflectionClass('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 = new LoggingTranslatorPass();
|
||||||
$pass->process($container);
|
$pass->process($container);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user