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

Breadcrumb

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

class Iterator

Same name in this branch
  1. 11.1.x vendor/phpunit/php-code-coverage/src/Node/Iterator.php \SebastianBergmann\CodeCoverage\Node\Iterator

@template-extends FilterIterator<int, string, AppendIterator>

@internal This class is not covered by the backward compatibility promise for phpunit/php-file-iterator

Hierarchy

  • class \SebastianBergmann\FileIterator\Iterator extends \FilterIterator

Expanded class hierarchy of Iterator

11 string references to 'Iterator'
Container::resolveServicesAndParameters in core/lib/Drupal/Component/DependencyInjection/Container.php
Resolves arguments that represent services or variables to the real values.
DebugClassLoader::setReturnType in vendor/symfony/error-handler/DebugClassLoader.php
Migration::findMigrationDependencies in core/modules/migrate/src/Plugin/Migration.php
Find migration dependencies from migration_lookup and sub_process plugins.
OptimizedPhpArrayDumper::getIterator in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Gets a service iterator in a suitable PHP array format.
PhpArrayContainer::resolveServicesAndParameters in core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php
Resolves arguments that represent services or variables to the real values.

... See full list

File

vendor/phpunit/php-file-iterator/src/Iterator.php, line 27

Namespace

SebastianBergmann\FileIterator
View source
final class Iterator extends FilterIterator {
    public const PREFIX = 0;
    public const SUFFIX = 1;
    private string|false $basePath;
    
    /**
     * @psalm-var list<string>
     */
    private array $suffixes;
    
    /**
     * @psalm-var list<string>
     */
    private array $prefixes;
    
    /**
     * @psalm-param list<string> $suffixes
     * @psalm-param list<string> $prefixes
     */
    public function __construct(string $basePath, \Iterator $iterator, array $suffixes = [], array $prefixes = []) {
        $this->basePath = realpath($basePath);
        $this->prefixes = $prefixes;
        $this->suffixes = $suffixes;
        parent::__construct($iterator);
    }
    public function accept() : bool {
        $current = $this->getInnerIterator()
            ->current();
        assert($current instanceof SplFileInfo);
        $filename = $current->getFilename();
        $realPath = $current->getRealPath();
        if ($realPath === false) {
            // @codeCoverageIgnoreStart
            return false;
            // @codeCoverageIgnoreEnd
        }
        return $this->acceptPath($realPath) && $this->acceptPrefix($filename) && $this->acceptSuffix($filename);
    }
    private function acceptPath(string $path) : bool {
        // Filter files in hidden directories by checking path that is relative to the base path.
        if (preg_match('=/\\.[^/]*/=', str_replace((string) $this->basePath, '', $path))) {
            return false;
        }
        return true;
    }
    private function acceptPrefix(string $filename) : bool {
        return $this->acceptSubString($filename, $this->prefixes, self::PREFIX);
    }
    private function acceptSuffix(string $filename) : bool {
        return $this->acceptSubString($filename, $this->suffixes, self::SUFFIX);
    }
    
    /**
     * @psalm-param list<string> $subStrings
     */
    private function acceptSubString(string $filename, array $subStrings, int $type) : bool {
        if (empty($subStrings)) {
            return true;
        }
        foreach ($subStrings as $string) {
            if ($type === self::PREFIX && str_starts_with($filename, $string) || $type === self::SUFFIX && str_ends_with($filename, $string)) {
                return true;
            }
        }
        return false;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Iterator::$basePath private property
Iterator::$prefixes private property @psalm-var list&lt;string&gt;
Iterator::$suffixes private property @psalm-var list&lt;string&gt;
Iterator::accept public function
Iterator::acceptPath private function
Iterator::acceptPrefix private function
Iterator::acceptSubString private function @psalm-param list&lt;string&gt; $subStrings
Iterator::acceptSuffix private function
Iterator::PREFIX public constant
Iterator::SUFFIX public constant
Iterator::__construct public function @psalm-param list&lt;string&gt; $suffixes
@psalm-param list&lt;string&gt; $prefixes
RSS feed
Powered by Drupal