FileResolverStub.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Config;
  7. use Magento\Framework\Config\FileIterator;
  8. use Magento\Framework\Filesystem\DriverPool;
  9. use Magento\Framework\Filesystem\File\ReadFactory;
  10. use Magento\Framework\Module\Dir;
  11. class FileResolverStub implements \Magento\Framework\Config\FileResolverInterface
  12. {
  13. /**
  14. * @var array
  15. */
  16. private $files = [
  17. 'etc/definition.xml' => [
  18. 'module_one/ui_component/etc/test_definition.xml',
  19. 'module_two/ui_component/etc/test_definition.xml'
  20. ],
  21. 'etc/definition.map.xml' => [
  22. 'ui_component/etc/definition.map.xml'
  23. ],
  24. 'etc/test_definition.xml' => [
  25. 'module_one/ui_component/etc/test_definition.xml',
  26. 'module_two/ui_component/etc/test_definition.xml'
  27. ],
  28. 'test_component.xml' => [
  29. 'module_one/ui_component/test_component.xml',
  30. 'module_two/ui_component/test_component.xml'
  31. ],
  32. 'parent_component.xml' => [
  33. 'module_one/ui_component/parent_component.xml',
  34. 'module_two/ui_component/parent_component.xml'
  35. ]
  36. ];
  37. /**
  38. * @var Dir\Reader
  39. */
  40. private $moduleReader;
  41. /**
  42. * FileResolverStub constructor.
  43. *
  44. * @param \Magento\Framework\Module\Dir\Reader $moduleReader
  45. * @param array $files
  46. */
  47. public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader, array $files = [])
  48. {
  49. $this->files = array_replace($this->files, $files);
  50. $this->moduleReader = $moduleReader;
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function get($filename, $scope)
  56. {
  57. if ($filename == 'etc/definition.map.xml') {
  58. $path = $this->moduleReader->getModuleDir(Dir::MODULE_VIEW_DIR, 'Magento_Ui') . '/base';
  59. } else {
  60. $path = realpath(__DIR__ . '/../_files/view');
  61. }
  62. $files = isset($this->files[$filename]) ? $this->files[$filename] : [];
  63. $realPaths = [];
  64. foreach ($files as $filePath) {
  65. $realPaths[] = $path . '/' . $filePath;
  66. }
  67. return new FileIterator(new ReadFactory(new DriverPool), $realPaths);
  68. }
  69. }