Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DirectoryScanner.php
Go to the documentation of this file.
1 <?php
7 
9 {
18  public function scan($dir, array $patterns = [], array $excludePatterns = [])
19  {
20  $recursiveIterator = new \RecursiveIteratorIterator(
21  new \RecursiveDirectoryIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS)
22  );
23  $output = [];
24  foreach ($recursiveIterator as $file) {
26  if ($file->isDir()) {
27  continue;
28  }
29 
30  $filePath = str_replace('\\', '/', $file->getRealPath());
31  if (!empty($excludePatterns)) {
32  foreach ($excludePatterns as $excludePattern) {
33  if (preg_match($excludePattern, $filePath)) {
34  continue 2;
35  }
36  }
37  }
38  foreach ($patterns as $type => $pattern) {
39  if (preg_match($pattern, $filePath)) {
40  $output[$type][] = $filePath;
41  break;
42  }
43  }
44  }
45  return $output;
46  }
47 }
$pattern
Definition: website.php:22
$type
Definition: item.phtml:13