You are here

class SizeRangeFilterIterator in Database Sanitize 7

SizeRangeFilterIterator filters out files that are not in the given size range.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of SizeRangeFilterIterator

2 files declare their use of SizeRangeFilterIterator
Finder.php in vendor/symfony/finder/Finder.php
SizeRangeFilterIteratorTest.php in vendor/symfony/finder/Tests/Iterator/SizeRangeFilterIteratorTest.php

File

vendor/symfony/finder/Iterator/SizeRangeFilterIterator.php, line 21

Namespace

Symfony\Component\Finder\Iterator
View source
class SizeRangeFilterIterator extends FilterIterator {
  private $comparators = array();

  /**
   * @param \Iterator          $iterator    The Iterator to filter
   * @param NumberComparator[] $comparators An array of NumberComparator instances
   */
  public function __construct(\Iterator $iterator, array $comparators) {
    $this->comparators = $comparators;
    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 (!$fileinfo
      ->isFile()) {
      return true;
    }
    $filesize = $fileinfo
      ->getSize();
    foreach ($this->comparators as $compare) {
      if (!$compare
        ->test($filesize)) {
        return false;
      }
    }
    return true;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
SizeRangeFilterIterator::$comparators private property
SizeRangeFilterIterator::accept public function Filters the iterator values.
SizeRangeFilterIterator::__construct public function