Geen omschrijving

TranslationExtractorPass.php 1.6KB

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