Base.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\File\Collector;
  7. use Magento\Framework\Component\ComponentRegistrar;
  8. use Magento\Framework\Component\DirSearch;
  9. use Magento\Framework\View\Design\ThemeInterface;
  10. use Magento\Framework\View\File\CollectorInterface;
  11. use Magento\Framework\View\File\Factory as FileFactory;
  12. /**
  13. * Source of base files introduced by modules
  14. */
  15. class Base implements CollectorInterface
  16. {
  17. /**
  18. * @var DirSearch
  19. */
  20. protected $componentDirSearch;
  21. /**
  22. * @var string
  23. */
  24. private $subDir;
  25. /**
  26. * @var FileFactory
  27. */
  28. private $fileFactory;
  29. /**
  30. * Constructor
  31. *
  32. * @param DirSearch $dirSearch
  33. * @param FileFactory $fileFactory
  34. * @param string $subDir
  35. */
  36. public function __construct(
  37. DirSearch $dirSearch,
  38. FileFactory $fileFactory,
  39. $subDir = ''
  40. ) {
  41. $this->componentDirSearch = $dirSearch;
  42. $this->fileFactory = $fileFactory;
  43. $this->subDir = $subDir ? $subDir . '/' : '';
  44. }
  45. /**
  46. * Retrieve files
  47. *
  48. * @param \Magento\Framework\View\Design\ThemeInterface $theme
  49. * @param string $filePath
  50. * @return \Magento\Framework\View\File[]
  51. */
  52. public function getFiles(ThemeInterface $theme, $filePath)
  53. {
  54. $result = [];
  55. $sharedFiles = $this->componentDirSearch->collectFilesWithContext(
  56. ComponentRegistrar::MODULE,
  57. "view/base/{$this->subDir}{$filePath}"
  58. );
  59. foreach ($sharedFiles as $file) {
  60. $result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName(), null, true);
  61. }
  62. $area = $theme->getData('area');
  63. $themeFiles = $this->componentDirSearch->collectFilesWithContext(
  64. ComponentRegistrar::MODULE,
  65. "view/{$area}/{$this->subDir}{$filePath}"
  66. );
  67. foreach ($themeFiles as $file) {
  68. $result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName());
  69. }
  70. return $result;
  71. }
  72. }