Skip to content

Commit

Permalink
[FrameworkBundle] Wire inner translator
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Jul 4, 2017
1 parent ddc4b20 commit a32cae5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Expand Up @@ -14,7 +14,6 @@
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;

Expand All @@ -39,7 +38,16 @@ public function process(ContainerBuilder $container)
}
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'));
}
}
}
Expand Down
Expand Up @@ -60,6 +60,22 @@ public function testProcess()
->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);
}
Expand Down

0 comments on commit a32cae5

Please sign in to comment.