Reader.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\ReportXml\Config;
  7. use Magento\Framework\Config\ReaderInterface;
  8. /**
  9. * A composite reader of reports configuration.
  10. *
  11. * Reads configuration data using declared readers.
  12. */
  13. class Reader implements ReaderInterface
  14. {
  15. /**
  16. * A list of declared readers.
  17. *
  18. * The list may be configured in each module via '/etc/di.xml'.
  19. *
  20. * @var ReaderInterface[]
  21. */
  22. private $readers;
  23. /**
  24. * @var Mapper
  25. */
  26. private $mapper;
  27. /**
  28. * @param Mapper $mapper
  29. * @param array $readers
  30. */
  31. public function __construct(
  32. Mapper $mapper,
  33. $readers = []
  34. ) {
  35. $this->readers = $readers;
  36. $this->mapper = $mapper;
  37. }
  38. /**
  39. * Reads configuration according to the given scope.
  40. *
  41. * @param string|null $scope
  42. * @return array
  43. */
  44. public function read($scope = null)
  45. {
  46. $data = [];
  47. foreach ($this->readers as $reader) {
  48. $data = array_merge_recursive($data, $reader->read($scope));
  49. }
  50. return $this->mapper->execute($data);
  51. }
  52. }