ChainExtractor.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Extractor;
  11. use Symfony\Component\Translation\MessageCatalogue;
  12. /**
  13. * ChainExtractor extracts translation messages from template files.
  14. *
  15. * @author Michel Salib <michelsalib@hotmail.com>
  16. */
  17. class ChainExtractor implements ExtractorInterface
  18. {
  19. /**
  20. * The extractors.
  21. *
  22. * @var ExtractorInterface[]
  23. */
  24. private $extractors = [];
  25. /**
  26. * Adds a loader to the translation extractor.
  27. */
  28. public function addExtractor(string $format, ExtractorInterface $extractor)
  29. {
  30. $this->extractors[$format] = $extractor;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function setPrefix(string $prefix)
  36. {
  37. foreach ($this->extractors as $extractor) {
  38. $extractor->setPrefix($prefix);
  39. }
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function extract($directory, MessageCatalogue $catalogue)
  45. {
  46. foreach ($this->extractors as $extractor) {
  47. $extractor->extract($directory, $catalogue);
  48. }
  49. }
  50. }