function CollectPathsToExcludeEvent::scanForDirectoriesByName

Finds all directories in the project root matching the given name.

Parameters

string $directory_name: A directory name.

Return value

string[] All discovered absolute paths matching the given directory name.

File

core/modules/package_manager/src/Event/CollectPathsToExcludeEvent.php, line 117

Class

CollectPathsToExcludeEvent
Defines an event that collects paths to exclude.

Namespace

Drupal\package_manager\Event

Code

public function scanForDirectoriesByName(string $directory_name) : array {
    $flags = \FilesystemIterator::UNIX_PATHS;
    $flags |= \FilesystemIterator::CURRENT_AS_SELF;
    $directories_tree = new \RecursiveDirectoryIterator($this->pathLocator
        ->getProjectRoot(), $flags);
    $filtered_directories = new \RecursiveIteratorIterator($directories_tree, \RecursiveIteratorIterator::SELF_FIRST);
    $matched_directories = new \CallbackFilterIterator($filtered_directories, fn(\RecursiveDirectoryIterator $current) => $current->isDir() && $current->getFilename() === $directory_name);
    return array_keys(iterator_to_array($matched_directories));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.