class RegexDirectoryIterator

Same name in other branches
  1. 9 core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php \Drupal\Component\FileSystem\RegexDirectoryIterator
  2. 8.9.x core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php \Drupal\Component\FileSystem\RegexDirectoryIterator
  3. 11.x core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php \Drupal\Component\FileSystem\RegexDirectoryIterator

Iterates over files whose names match a regular expression in a directory.

Hierarchy

Expanded class hierarchy of RegexDirectoryIterator

3 files declare their use of RegexDirectoryIterator
HelpTopicDiscovery.php in core/modules/help/src/HelpTopicDiscovery.php
RegexDirectoryIteratorTest.php in core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php
YamlDirectoryDiscovery.php in core/lib/Drupal/Component/Discovery/YamlDirectoryDiscovery.php

File

core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php, line 8

Namespace

Drupal\Component\FileSystem
View source
class RegexDirectoryIterator extends \RegexIterator {
    
    /**
     * RegexDirectoryIterator constructor.
     *
     * @param string $path
     *   The path to scan.
     * @param string $regex
     *   The regular expression to match, including delimiters. For example,
     *   /\.yml$/ would list only files ending in .yml.
     */
    public function __construct($path, $regex) {
        parent::__construct(new \FilesystemIterator($path), $regex);
    }
    
    /**
     * Implements \RegexIterator::accept().
     */
    public function accept() {
        
        /** @var \SplFileInfo $file_info */
        $file_info = $this->getInnerIterator()
            ->current();
        return $file_info->isFile() && preg_match($this->getRegex(), $file_info->getFilename());
    }

}

Members

Title Sort descending Modifiers Object type Summary
RegexDirectoryIterator::accept public function Implements \RegexIterator::accept().
RegexDirectoryIterator::__construct public function RegexDirectoryIterator constructor.

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