You are here

public function FileSystem::scanDirectory in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::scanDirectory()
  2. 9 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::scanDirectory()

File

core/lib/Drupal/Core/File/FileSystem.php, line 655

Class

FileSystem
Provides helpers to operate on files and stream wrappers.

Namespace

Drupal\Core\File

Code

public function scanDirectory($dir, $mask, array $options = []) {

  // Merge in defaults.
  $options += [
    'callback' => 0,
    'recurse' => TRUE,
    'key' => 'uri',
    'min_depth' => 0,
  ];
  $dir = $this->streamWrapperManager
    ->normalizeUri($dir);
  if (!is_dir($dir)) {
    throw new NotRegularDirectoryException("{$dir} is not a directory.");
  }

  // Allow directories specified in settings.php to be ignored. You can use
  // this to not check for files in common special-purpose directories. For
  // example, node_modules and bower_components. Ignoring irrelevant
  // directories is a performance boost.
  if (!isset($options['nomask'])) {
    $ignore_directories = $this->settings
      ->get('file_scan_ignore_directories', []);
    array_walk($ignore_directories, function (&$value) {
      $value = preg_quote($value, '/');
    });
    $options['nomask'] = '/^' . implode('|', $ignore_directories) . '$/';
  }
  $options['key'] = in_array($options['key'], [
    'uri',
    'filename',
    'name',
  ]) ? $options['key'] : 'uri';
  return $this
    ->doScanDirectory($dir, $mask, $options);
}