Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Base.php
Go to the documentation of this file.
1 <?php
7 
14 use Magento\Framework\View\File\Factory as FileFactory;
16 
20 class Base implements CollectorInterface
21 {
27  private $pathPatternHelper;
28 
34  private $fileFactory;
35 
41  private $readDirFactory;
42 
48  private $componentRegistrar;
49 
55  private $subDir;
56 
66  public function __construct(
67  FileFactory $fileFactory,
68  ReadFactory $readDirFactory,
69  ComponentRegistrarInterface $componentRegistrar,
70  PathPattern $pathPatternHelper,
71  $subDir = ''
72  ) {
73  $this->pathPatternHelper = $pathPatternHelper;
74  $this->fileFactory = $fileFactory;
75  $this->readDirFactory = $readDirFactory;
76  $this->componentRegistrar = $componentRegistrar;
77  $this->subDir = $subDir ? $subDir . '/' : '';
78  }
79 
87  public function getFiles(ThemeInterface $theme, $filePath)
88  {
89  $namespace = $module = '*';
90  $themePath = $theme->getFullPath();
91  if (empty($themePath)) {
92  return [];
93  }
94  $themeAbsolutePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath);
95  if (!$themeAbsolutePath) {
96  return [];
97  }
98  $themeDir = $this->readDirFactory->create($themeAbsolutePath);
99  $searchPattern = "{$namespace}_{$module}/{$this->subDir}{$filePath}";
100  $files = $themeDir->search($searchPattern);
101  $result = [];
102  $pattern = "#(?<moduleName>[^/]+)/{$this->subDir}"
103  . $this->pathPatternHelper->translatePatternFromGlob($filePath) . "$#i";
104  foreach ($files as $file) {
105  $filename = $themeDir->getAbsolutePath($file);
106  if (!preg_match($pattern, $filename, $matches)) {
107  continue;
108  }
109  $result[] = $this->fileFactory->create($filename, $matches['moduleName']);
110  }
111  return $result;
112  }
113 }
__construct(FileFactory $fileFactory, ReadFactory $readDirFactory, ComponentRegistrarInterface $componentRegistrar, PathPattern $pathPatternHelper, $subDir='')
Definition: Base.php:66
$componentRegistrar
Definition: bootstrap.php:23
$pattern
Definition: website.php:22
getFiles(ThemeInterface $theme, $filePath)
Definition: Base.php:87
foreach($appDirs as $dir) $files