function FileSystem::scanDirectory
Same name in other branches
- 9 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::scanDirectory()
- 10 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::scanDirectory()
- 11.x core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::scanDirectory()
Overrides FileSystemInterface::scanDirectory
File
-
core/
lib/ Drupal/ Core/ File/ FileSystem.php, line 679
Class
- FileSystem
- Provides helpers to operate on files and stream wrappers.
Namespace
Drupal\Core\FileCode
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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.