Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / finder / Iterator / SizeRangeFilterIterator.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Finder\Iterator;
13
14 use Symfony\Component\Finder\Comparator\NumberComparator;
15
16 /**
17  * SizeRangeFilterIterator filters out files that are not in the given size range.
18  *
19  * @author Fabien Potencier <fabien@symfony.com>
20  */
21 class SizeRangeFilterIterator extends FilterIterator
22 {
23     private $comparators = array();
24
25     /**
26      * @param \Iterator          $iterator    The Iterator to filter
27      * @param NumberComparator[] $comparators An array of NumberComparator instances
28      */
29     public function __construct(\Iterator $iterator, array $comparators)
30     {
31         $this->comparators = $comparators;
32
33         parent::__construct($iterator);
34     }
35
36     /**
37      * Filters the iterator values.
38      *
39      * @return bool true if the value should be kept, false otherwise
40      */
41     public function accept()
42     {
43         $fileinfo = $this->current();
44         if (!$fileinfo->isFile()) {
45             return true;
46         }
47
48         $filesize = $fileinfo->getSize();
49         foreach ($this->comparators as $compare) {
50             if (!$compare->test($filesize)) {
51                 return false;
52             }
53         }
54
55         return true;
56     }
57 }