CompositeReader.php 1.2 KB

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