Skip to content

Commit

Permalink
bug #23370 [FrameworkBundle] Wire inner translator (ogizanagi)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle] Wire inner translator

| Q             | A
| ------------- | ---
| Branch?       | 3.4 <!-- see comment below -->
| Bug fix?      | yes
| New feature?  | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #23293 (comment)
| License       | MIT
| Doc PR        | N/A

Commits
-------

a32cae5 [FrameworkBundle] Wire inner translator
  • Loading branch information
fabpot committed Jul 4, 2017
2 parents ddc4b20 + a32cae5 commit a1c77e7
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 a1c77e7

Please sign in to comment.