TranslationExtractorPass.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. /**
  15. * Adds tagged translation.extractor services to translation extractor.
  16. */
  17. class TranslationExtractorPass implements CompilerPassInterface
  18. {
  19. public function process(ContainerBuilder $container)
  20. {
  21. if (!$container->hasDefinition('translation.extractor')) {
  22. return;
  23. }
  24. $definition = $container->getDefinition('translation.extractor');
  25. foreach ($container->findTaggedServiceIds('translation.extractor') as $id => $attributes) {
  26. if (!isset($attributes[0]['alias'])) {
  27. throw new \RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
  28. }
  29. $definition->addMethodCall('addExtractor', array($attributes[0]['alias'], new Reference($id)));
  30. }
  31. }
  32. }