ChainExtractor.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. * @param string $format The format of the loader
  29. */
  30. public function addExtractor(string $format, ExtractorInterface $extractor)
  31. {
  32. $this->extractors[$format] = $extractor;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function setPrefix(string $prefix)
  38. {
  39. foreach ($this->extractors as $extractor) {
  40. $extractor->setPrefix($prefix);
  41. }
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function extract($directory, MessageCatalogue $catalogue)
  47. {
  48. foreach ($this->extractors as $extractor) {
  49. $extractor->extract($directory, $catalogue);
  50. }
  51. }
  52. }