CompositeReader.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Consumer\Config;
  7. use Magento\Framework\MessageQueue\Consumer\Config\ReaderInterface;
  8. use Magento\Framework\Phrase;
  9. use Magento\Framework\MessageQueue\Consumer\Config\ValidatorInterface;
  10. /**
  11. * Composite reader for consumer config.
  12. */
  13. class CompositeReader implements ReaderInterface
  14. {
  15. /**
  16. * @var ValidatorInterface
  17. */
  18. private $validator;
  19. /**
  20. * @var ReaderInterface[]
  21. */
  22. private $readers;
  23. /**
  24. * Initialize dependencies.
  25. *
  26. * @param ValidatorInterface $validator
  27. * @param ReaderInterface[] $readers
  28. */
  29. public function __construct(ValidatorInterface $validator, array $readers)
  30. {
  31. $this->validator = $validator;
  32. $this->readers = $readers;
  33. }
  34. /**
  35. * Read config.
  36. *
  37. * @param string|null $scope
  38. * @return array
  39. */
  40. public function read($scope = null)
  41. {
  42. $result = [];
  43. foreach ($this->readers as $reader) {
  44. $result = array_replace_recursive($result, $reader->read($scope));
  45. }
  46. $this->validator->validate($result);
  47. return $result;
  48. }
  49. }