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

Breadcrumb

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

function Finder::getIterator

Returns an Iterator for the current Finder configuration.

This method implements the IteratorAggregate interface.

Return value

\Iterator<string, SplFileInfo>

Throws

\LogicException if the in() method has not been called

2 calls to Finder::getIterator()
Finder::count in vendor/symfony/finder/Finder.php
Counts all the results collected by the iterators.
Finder::hasResults in vendor/symfony/finder/Finder.php
Check if any results were found.

File

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

Class

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

Namespace

Symfony\Component\Finder

Code

public function getIterator() : \Iterator {
    if (0 === \count($this->dirs) && 0 === \count($this->iterators)) {
        throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
    }
    if (1 === \count($this->dirs) && 0 === \count($this->iterators)) {
        $iterator = $this->searchInDirectory($this->dirs[0]);
        if ($this->sort || $this->reverseSorting) {
            $iterator = (new SortableIterator($iterator, $this->sort, $this->reverseSorting))
                ->getIterator();
        }
        return $iterator;
    }
    $iterator = new \AppendIterator();
    foreach ($this->dirs as $dir) {
        $iterator->append(new \IteratorIterator(new LazyIterator(fn() => $this->searchInDirectory($dir))));
    }
    foreach ($this->iterators as $it) {
        $iterator->append($it);
    }
    if ($this->sort || $this->reverseSorting) {
        $iterator = (new SortableIterator($iterator, $this->sort, $this->reverseSorting))
            ->getIterator();
    }
    return $iterator;
}

API Navigation

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