TranslationExtractorPass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /**
  21. * @return void
  22. */
  23. public function process(ContainerBuilder $container)
  24. {
  25. if (!$container->hasDefinition('translation.extractor')) {
  26. return;
  27. }
  28. $definition = $container->getDefinition('translation.extractor');
  29. foreach ($container->findTaggedServiceIds('translation.extractor', true) as $id => $attributes) {
  30. if (!isset($attributes[0]['alias'])) {
  31. throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
  32. }
  33. $definition->addMethodCall('addExtractor', [$attributes[0]['alias'], new Reference($id)]);
  34. }
  35. }
  36. }