class RegexRecursiveFilterIterator
Same name in this branch
- 11.x core/lib/Drupal/Core/Plugin/Discovery/RegexRecursiveFilterIterator.php \Drupal\Core\Plugin\Discovery\RegexRecursiveFilterIterator
Same name in other branches
- 10 core/modules/sdc/src/Plugin/Discovery/RegexRecursiveFilterIterator.php \Drupal\sdc\Plugin\Discovery\RegexRecursiveFilterIterator
- 10 core/lib/Drupal/Core/Plugin/Discovery/RegexRecursiveFilterIterator.php \Drupal\Core\Plugin\Discovery\RegexRecursiveFilterIterator
Iterates over files whose names match a regular expression in a directory.
@internal
Hierarchy
- class \Drupal\sdc\Plugin\Discovery\RegexRecursiveFilterIterator extends \Drupal\sdc\Plugin\Discovery\RecursiveFilterIterator
Expanded class hierarchy of RegexRecursiveFilterIterator
File
-
core/
modules/ sdc/ src/ Plugin/ Discovery/ RegexRecursiveFilterIterator.php, line 10
Namespace
Drupal\sdc\Plugin\DiscoveryView source
final class RegexRecursiveFilterIterator extends \RecursiveFilterIterator {
/**
* RegexDirectoryIterator constructor.
*
* @param \RecursiveIterator $iterator
* The iterator.
* @param string $regex
* The regular expression to match, including delimiters. For example,
* /\.yml$/ would list only files ending in .yml.
*/
public function __construct(\RecursiveIterator $iterator, string $regex = '') {
parent::__construct($iterator);
}
/**
* {@inheritdoc}
*/
public function accept() {
/** @var \SplFileInfo $file_info */
$file_info = $this->getInnerIterator()
->current();
if ($file_info->isDir()) {
// Enter into subdirectory.
return TRUE;
}
// Return if file matches regular expression.
return $file_info->isFile() && preg_match($this->regex, $file_info->getFilename());
}
/**
* {@inheritdoc}
*/
public function getChildren() {
$children = parent::getChildren();
if ($children instanceof self && empty($children->regex)) {
$children->regex = $this->regex;
}
return $children;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
RegexRecursiveFilterIterator::accept | public | function | |
RegexRecursiveFilterIterator::getChildren | public | function | |
RegexRecursiveFilterIterator::__construct | public | function | RegexDirectoryIterator constructor. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.