You are here

class FileTypeFilterIterator in Database Sanitize 7

FileTypeFilterIterator only keeps files, directories, or both.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of FileTypeFilterIterator

1 file declares its use of FileTypeFilterIterator
FileTypeFilterIteratorTest.php in vendor/symfony/finder/Tests/Iterator/FileTypeFilterIteratorTest.php

File

vendor/symfony/finder/Iterator/FileTypeFilterIterator.php, line 19

Namespace

Symfony\Component\Finder\Iterator
View source
class FileTypeFilterIterator extends FilterIterator {
  const ONLY_FILES = 1;
  const ONLY_DIRECTORIES = 2;
  private $mode;

  /**
   * @param \Iterator $iterator The Iterator to filter
   * @param int       $mode     The mode (self::ONLY_FILES or self::ONLY_DIRECTORIES)
   */
  public function __construct(\Iterator $iterator, $mode) {
    $this->mode = $mode;
    parent::__construct($iterator);
  }

  /**
   * Filters the iterator values.
   *
   * @return bool true if the value should be kept, false otherwise
   */
  public function accept() {
    $fileinfo = $this
      ->current();
    if (self::ONLY_DIRECTORIES === (self::ONLY_DIRECTORIES & $this->mode) && $fileinfo
      ->isFile()) {
      return false;
    }
    elseif (self::ONLY_FILES === (self::ONLY_FILES & $this->mode) && $fileinfo
      ->isDir()) {
      return false;
    }
    return true;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileTypeFilterIterator::$mode private property
FileTypeFilterIterator::accept public function Filters the iterator values.
FileTypeFilterIterator::ONLY_DIRECTORIES constant
FileTypeFilterIterator::ONLY_FILES constant
FileTypeFilterIterator::__construct public function
FilterIterator::rewind public function This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after rewind in some cases. Overrides FilterIterator::rewind 1