4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Iterator
;
15 * CustomFilterIterator filters files by applying anonymous functions.
17 * The anonymous function receives a \SplFileInfo and must return false
20 * @author Fabien Potencier <fabien@symfony.com>
22 class CustomFilterIterator
extends FilterIterator
24 private $filters = array();
29 * @param \Iterator $iterator The Iterator to filter
30 * @param callable[] $filters An array of PHP callbacks
32 * @throws \InvalidArgumentException
34 public function __construct(\Iterator
$iterator, array $filters)
36 foreach ($filters as $filter) {
37 if (!is_callable($filter)) {
38 throw new \
InvalidArgumentException('Invalid PHP callback.');
41 $this->filters
= $filters;
43 parent
::__construct($iterator);
47 * Filters the iterator values.
49 * @return bool true if the value should be kept, false otherwise
51 public function accept()
53 $fileinfo = $this->current();
55 foreach ($this->filters
as $filter) {
56 if (false === call_user_func($filter, $fileinfo)) {