Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Library.php
Go to the documentation of this file.
1 <?php
7 
15 
19 class Library implements CollectorInterface
20 {
24  protected $fileFactory;
25 
29  protected $libraryDirectory;
30 
34  protected $fileListFactory;
35 
39  private $readFactory;
40 
46  private $componentRegistrar;
47 
55  public function __construct(
56  \Magento\Framework\View\File\FileList\Factory $fileListFactory,
58  \Magento\Framework\View\File\Factory $fileFactory,
59  \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
60  ComponentRegistrarInterface $componentRegistrar
61  ) {
62  $this->fileListFactory = $fileListFactory;
63  $this->libraryDirectory = $filesystem->getDirectoryRead(
65  );
66  $this->fileFactory = $fileFactory;
67  $this->readFactory = $readFactory;
68  $this->componentRegistrar = $componentRegistrar;
69  }
70 
78  public function getFiles(ThemeInterface $theme, $filePath)
79  {
80  $list = $this->fileListFactory->create(\Magento\Framework\Css\PreProcessor\File\FileList\Collator::class);
81  $files = $this->libraryDirectory->search($filePath);
82  $list->add($this->createFiles($this->libraryDirectory, $theme, $files));
83 
84  foreach ($theme->getInheritedThemes() as $currentTheme) {
85  $themeFullPath = $currentTheme->getFullPath();
86  $path = $this->componentRegistrar->getPath(
88  $themeFullPath
89  );
90  if (empty($path)) {
91  continue;
92  }
93  $directoryRead = $this->readFactory->create($path);
94  $foundFiles = $directoryRead->search("web/{$filePath}");
95  $list->replace($this->createFiles($directoryRead, $theme, $foundFiles));
96  }
97  return $list->getAll();
98  }
99 
106  protected function createFiles(ReadInterface $reader, ThemeInterface $theme, $files)
107  {
108  $result = [];
109  foreach ($files as $file) {
110  $filename = $reader->getAbsolutePath($file);
111  $result[] = $this->fileFactory->create($filename, false, $theme);
112  }
113  return $result;
114  }
115 }
$componentRegistrar
Definition: bootstrap.php:23
createFiles(ReadInterface $reader, ThemeInterface $theme, $files)
Definition: Library.php:106
$theme
getFiles(ThemeInterface $theme, $filePath)
Definition: Library.php:78
$filesystem
foreach($appDirs as $dir) $files
__construct(\Magento\Framework\View\File\FileList\Factory $fileListFactory, Filesystem $filesystem, \Magento\Framework\View\File\Factory $fileFactory, \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory, ComponentRegistrarInterface $componentRegistrar)
Definition: Library.php:55