function DirectoryWithMetadataDiscovery::getDirectoryIterator

Same name in this branch
  1. 10 core/lib/Drupal/Core/Plugin/Discovery/DirectoryWithMetadataDiscovery.php \Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery::getDirectoryIterator()
Same name in other branches
  1. 11.x core/modules/sdc/src/Plugin/Discovery/DirectoryWithMetadataDiscovery.php \Drupal\sdc\Plugin\Discovery\DirectoryWithMetadataDiscovery::getDirectoryIterator()
  2. 11.x core/lib/Drupal/Core/Plugin/Discovery/DirectoryWithMetadataDiscovery.php \Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery::getDirectoryIterator()

Gets an iterator to loop over the files in the provided directory.

This method exists so that it is easy to replace this functionality in a class that extends this one. For example, it could be used to make the scan recursive.

Parameters

string $directory: The directory to scan.

Return value

\RecursiveIteratorIterator A \RecursiveIteratorIterator object or array where the values are \SplFileInfo objects.

Overrides YamlDirectoryDiscovery::getDirectoryIterator

File

core/modules/sdc/src/Plugin/Discovery/DirectoryWithMetadataDiscovery.php, line 46

Class

DirectoryWithMetadataDiscovery
Does the actual finding of the directories with metadata files.

Namespace

Drupal\sdc\Plugin\Discovery

Code

protected function getDirectoryIterator($directory) : \RecursiveIteratorIterator {
    // Use FilesystemIterator to not iterate over the . and .. directories.
    $flags = \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS;
    $directory_iterator = new \RecursiveDirectoryIterator($directory, $flags);
    // Detect "my_component.component.yml".
    $regex = '/^([a-z0-9_-])+.component.yml$/i';
    $filter = new RegexRecursiveFilterIterator($directory_iterator, $regex);
    return new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::LEAVES_ONLY, $flags);
}

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