Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Mask.php
Go to the documentation of this file.
1 <?php
8 
12 
17 class Mask implements FileResolverInterface
18 {
24  protected $moduleResolver;
25 
31  public function __construct(ModuleResolver $moduleResolver = null)
32  {
33  if ($moduleResolver) {
34  $this->moduleResolver = $moduleResolver;
35  } else {
36  $this->moduleResolver = ModuleResolver::getInstance();
37  }
38  }
39 
47  public function get($filename, $scope)
48  {
49  $paths = $this->getFileCollection($filename, $scope);
50 
51  return new File($paths);
52  }
53 
61  protected function getFileCollection($filename, $scope)
62  {
63  $paths = [];
64  $modulesPath = $this->moduleResolver->getModulesPath();
65 
66  foreach ($modulesPath as $modulePath) {
67  $path = $modulePath . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR;
68  if (is_readable($path)) {
69  $directoryIterator = new \RecursiveIteratorIterator(
70  new \RecursiveDirectoryIterator(
71  $path,
72  \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
73  )
74  );
75  $regexpIterator = new \RegexIterator($directoryIterator, $filename);
77  foreach ($regexpIterator as $file) {
78  if ($file->isFile() && $file->isReadable()) {
79  $paths[] = $file->getRealPath();
80  }
81  }
82  }
83  }
84 
85  return $this->moduleResolver->sortFilesByModuleSequence($paths);
86  }
87 }
__construct(ModuleResolver $moduleResolver=null)
Definition: Mask.php:31
$paths
Definition: _bootstrap.php:83