Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DirSearch.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class DirSearch
14 {
20  private $registrar;
21 
27  private $readFactory;
28 
35  public function __construct(ComponentRegistrarInterface $registrar, Filesystem\Directory\ReadFactory $readFactory)
36  {
37  $this->registrar = $registrar;
38  $this->readFactory = $readFactory;
39  }
40 
48  public function collectFiles($componentType, $pattern)
49  {
50  return $this->collect($componentType, $pattern, false);
51  }
52 
60  public function collectFilesWithContext($componentType, $pattern)
61  {
62  return $this->collect($componentType, $pattern, true);
63  }
64 
74  private function collect($componentType, $pattern, $withContext)
75  {
76  $files = [];
77  foreach ($this->registrar->getPaths($componentType) as $componentName => $path) {
78  $directoryRead = $this->readFactory->create($path);
79  $foundFiles = $directoryRead->search($pattern);
80  foreach ($foundFiles as $foundFile) {
81  $foundFile = $directoryRead->getAbsolutePath($foundFile);
82  if ($withContext) {
83  $files[] = new ComponentFile($componentType, $componentName, $foundFile);
84  } else {
85  $files[] = $foundFile;
86  }
87  }
88  }
89  return $files;
90  }
91 }
__construct(ComponentRegistrarInterface $registrar, Filesystem\Directory\ReadFactory $readFactory)
Definition: DirSearch.php:35
$pattern
Definition: website.php:22
collectFiles($componentType, $pattern)
Definition: DirSearch.php:48
$registrar
Definition: registration.php:9
collectFilesWithContext($componentType, $pattern)
Definition: DirSearch.php:60
foreach($appDirs as $dir) $files