TranslatorPass.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. class TranslatorPass implements CompilerPassInterface
  15. {
  16. public function process(ContainerBuilder $container)
  17. {
  18. if (!$container->hasDefinition('translator.default')) {
  19. return;
  20. }
  21. $loaders = array();
  22. foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
  23. $loaders[$id][] = $attributes[0]['alias'];
  24. if (isset($attributes[0]['legacy-alias'])) {
  25. $loaders[$id][] = $attributes[0]['legacy-alias'];
  26. }
  27. }
  28. if ($container->hasDefinition('translation.loader')) {
  29. $definition = $container->getDefinition('translation.loader');
  30. foreach ($loaders as $id => $formats) {
  31. foreach ($formats as $format) {
  32. $definition->addMethodCall('addLoader', array($format, new Reference($id)));
  33. }
  34. }
  35. }
  36. $container->findDefinition('translator.default')->replaceArgument(2, $loaders);
  37. }
  38. }