You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

3 years ago
  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\Reference;
  14. /**
  15. * Adds tagged translation.formatter services to translation writer.
  16. */
  17. class TranslationDumperPass implements CompilerPassInterface
  18. {
  19. private $writerServiceId;
  20. private $dumperTag;
  21. public function __construct(string $writerServiceId = 'translation.writer', string $dumperTag = 'translation.dumper')
  22. {
  23. if (1 < \func_num_args()) {
  24. trigger_deprecation('symfony/translation', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
  25. }
  26. $this->writerServiceId = $writerServiceId;
  27. $this->dumperTag = $dumperTag;
  28. }
  29. public function process(ContainerBuilder $container)
  30. {
  31. if (!$container->hasDefinition($this->writerServiceId)) {
  32. return;
  33. }
  34. $definition = $container->getDefinition($this->writerServiceId);
  35. foreach ($container->findTaggedServiceIds($this->dumperTag, true) as $id => $attributes) {
  36. $definition->addMethodCall('addDumper', [$attributes[0]['alias'], new Reference($id)]);
  37. }
  38. }
  39. }