Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Theme.php
Go to the documentation of this file.
1 <?php
7 
13 use Magento\Framework\View\File\Factory as FileFactory;
14 
18 class Theme implements CollectorInterface
19 {
23  private $fileFactory;
24 
28  private $readDirFactory;
29 
33  private $componentRegistrar;
34 
38  private $subDir;
39 
48  public function __construct(
49  FileFactory $fileFactory,
50  ReadFactory $readDirFactory,
51  ComponentRegistrarInterface $componentRegistrar,
52  $subDir = ''
53  ) {
54  $this->fileFactory = $fileFactory;
55  $this->readDirFactory = $readDirFactory;
56  $this->componentRegistrar = $componentRegistrar;
57  $this->subDir = $subDir ? $subDir . '/' : '';
58  }
59 
68  public function getFiles(ThemeInterface $theme, $filePath)
69  {
70  $themePath = $theme->getFullPath();
71  if (empty($themePath)) {
72  return [];
73  }
74  $themeAbsolutePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath);
75  if (!$themeAbsolutePath) {
76  return [];
77  }
78  $themeDir = $this->readDirFactory->create($themeAbsolutePath);
79  $files = $themeDir->search($this->subDir . $filePath);
80  $result = [];
81  foreach ($files as $file) {
82  $filename = $themeDir->getAbsolutePath($file);
83  $result[] = $this->fileFactory->create($filename, null, $theme);
84  }
85  return $result;
86  }
87 }
$componentRegistrar
Definition: bootstrap.php:23
getFiles(ThemeInterface $theme, $filePath)
Definition: Theme.php:68
__construct(FileFactory $fileFactory, ReadFactory $readDirFactory, ComponentRegistrarInterface $componentRegistrar, $subDir='')
Definition: Theme.php:48
foreach($appDirs as $dir) $files