Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Finder.php

function Finder::searchInDirectory

1 call to Finder::searchInDirectory()
Finder::getIterator in vendor/symfony/finder/Finder.php
Returns an Iterator for the current Finder configuration.

File

vendor/symfony/finder/Finder.php, line 741

Class

Finder
Finder allows to build rules to find files and directories.

Namespace

Symfony\Component\Finder

Code

private function searchInDirectory(string $dir) : \Iterator {
    $exclude = $this->exclude;
    $notPaths = $this->notPaths;
    if ($this->pruneFilters) {
        $exclude = array_merge($exclude, $this->pruneFilters);
    }
    if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
        $exclude = array_merge($exclude, self::$vcsPatterns);
    }
    if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
        $notPaths[] = '#(^|/)\\..+(/|$)#';
    }
    $minDepth = 0;
    $maxDepth = \PHP_INT_MAX;
    foreach ($this->depths as $comparator) {
        switch ($comparator->getOperator()) {
            case '>':
                $minDepth = $comparator->getTarget() + 1;
                break;
            case '>=':
                $minDepth = $comparator->getTarget();
                break;
            case '<':
                $maxDepth = $comparator->getTarget() - 1;
                break;
            case '<=':
                $maxDepth = $comparator->getTarget();
                break;
            default:
                $minDepth = $maxDepth = $comparator->getTarget();
        }
    }
    $flags = \RecursiveDirectoryIterator::SKIP_DOTS;
    if ($this->followLinks) {
        $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
    }
    $iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
    if ($exclude) {
        $iterator = new ExcludeDirectoryFilterIterator($iterator, $exclude);
    }
    $iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
    if ($minDepth > 0 || $maxDepth < \PHP_INT_MAX) {
        $iterator = new DepthRangeFilterIterator($iterator, $minDepth, $maxDepth);
    }
    if ($this->mode) {
        $iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
    }
    if ($this->names || $this->notNames) {
        $iterator = new FilenameFilterIterator($iterator, $this->names, $this->notNames);
    }
    if ($this->contains || $this->notContains) {
        $iterator = new FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
    }
    if ($this->sizes) {
        $iterator = new SizeRangeFilterIterator($iterator, $this->sizes);
    }
    if ($this->dates) {
        $iterator = new DateRangeFilterIterator($iterator, $this->dates);
    }
    if ($this->filters) {
        $iterator = new CustomFilterIterator($iterator, $this->filters);
    }
    if ($this->paths || $notPaths) {
        $iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $notPaths);
    }
    if (static::IGNORE_VCS_IGNORED_FILES === (static::IGNORE_VCS_IGNORED_FILES & $this->ignore)) {
        $iterator = new Iterator\VcsIgnoredFilterIterator($iterator, $dir);
    }
    return $iterator;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal