Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThemeModular.php
Go to the documentation of this file.
1 <?php
7 
13 use Magento\Framework\View\File\Factory as FileFactory;
15 
20 {
24  private $pathPatternHelper;
25 
29  private $fileFactory;
30 
34  private $readDirFactory;
35 
39  private $componentRegistrar;
40 
44  private $subDir;
45 
55  public function __construct(
56  FileFactory $fileFactory,
57  ReadFactory $readDirFactory,
58  ComponentRegistrarInterface $componentRegistrar,
59  PathPattern $pathPatternHelper,
60  $subDir = ''
61  ) {
62  $this->pathPatternHelper = $pathPatternHelper;
63  $this->fileFactory = $fileFactory;
64  $this->readDirFactory = $readDirFactory;
65  $this->componentRegistrar = $componentRegistrar;
66  $this->subDir = $subDir ? $subDir . '/' : '';
67  }
68 
76  public function getFiles(ThemeInterface $theme, $filePath)
77  {
78  $namespace = $module = '*';
79  $themePath = $theme->getFullPath();
80  if (empty($themePath)) {
81  return [];
82  }
83  $themeAbsolutePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath);
84  if (!$themeAbsolutePath) {
85  return [];
86  }
87  $themeDir = $this->readDirFactory->create($themeAbsolutePath);
88  $files = $themeDir->search("{$namespace}_{$module}/{$this->subDir}$filePath");
89  $result = [];
90  $pattern = "#/(?<moduleName>[^/]+)/{$this->subDir}"
91  . $this->pathPatternHelper->translatePatternFromGlob($filePath) . "$#i";
92  foreach ($files as $file) {
93  $filename = $themeDir->getAbsolutePath($file);
94  if (!preg_match($pattern, $filename, $matches)) {
95  continue;
96  }
97  $result[] = $this->fileFactory->create($filename, $matches['moduleName'], $theme);
98  }
99  return $result;
100  }
101 }
$componentRegistrar
Definition: bootstrap.php:23
getFiles(ThemeInterface $theme, $filePath)
$pattern
Definition: website.php:22
foreach($appDirs as $dir) $files
__construct(FileFactory $fileFactory, ReadFactory $readDirFactory, ComponentRegistrarInterface $componentRegistrar, PathPattern $pathPatternHelper, $subDir='')