TranslationExtractorPass.php 1.3 KB

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