1.20.x bootstrap.inc | backdrop_scan_directories($mask, $searchdir, $key = 'name', $min_depth = -1) |
File
- includes/
bootstrap.inc, line 4301 - Functions that need to be loaded on every Backdrop request.
Code
function backdrop_scan_directories($mask, $searchdir, $key = 'name', $min_depth = -1) {
$files = array();
// Do not check for system files in common special-purpose directories.
$ignore_directories = array(
'assets',
'css',
'scss',
'less',
'js',
'images',
'templates',
'node_modules',
'bower_components',
);
$no_mask = '/^((\..*)|' . implode('|', $ignore_directories) . ')$/';
// Get current list of items.
if (!function_exists('file_scan_directory')) {
require_once BACKDROP_ROOT . '/core/includes/file.inc';
}
foreach ($searchdir as $dir) {
$files_to_add = file_scan_directory($dir, $mask, array('key' => $key, 'min_depth' => $min_depth, 'nomask' => $no_mask));
// Duplicate files found in later search directories take precedence over
// earlier ones, so we want them to overwrite keys in our resulting
// $files array.
// The exception to this is if the later file is from a module or theme not
// compatible with Backdrop core. This may occur during upgrades of Backdrop
// core when new modules exist in core while older contrib modules with the
// same name exist in a directory such as /modules.
foreach (array_intersect_key($files_to_add, $files) as $file_key => $file) {
// If it has no info file, then we just behave liberally and accept the
// new resource on the list for merging.
if (file_exists($info_file = dirname($file->uri) . '/' . $file->name . '.info')) {
// Get the .info file for the module or theme this file belongs to.
$info = backdrop_parse_info_file($info_file);
// If the module or theme is incompatible with Backdrop core, remove it
// from the array for the current search directory, so it is not
// overwritten when merged with the $files array.
if (isset($info['backdrop']) && $info['backdrop'] != BACKDROP_CORE_COMPATIBILITY) {
unset($files_to_add[$file_key]);
}
}
}
$files = array_merge($files, $files_to_add);
}
return $files;
}