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 * This iterator just overrides the rewind method in order to correct a PHP bug,
16 * which existed before version 5.5.23/5.6.7.
18 * @see https://bugs.php.net/68557
20 * @author Alex Bogomazov
22 abstract class FilterIterator extends \FilterIterator
25 * This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after
26 * rewind in some cases.
28 * @see FilterIterator::rewind()
30 public function rewind()
32 if (\PHP_VERSION_ID > 50607 || (\PHP_VERSION_ID > 50523 && \PHP_VERSION_ID < 50600)) {
39 while ($iterator instanceof \OuterIterator) {
40 $innerIterator = $iterator->getInnerIterator();
42 if ($innerIterator instanceof RecursiveDirectoryIterator) {
43 // this condition is necessary for iterators to work properly with non-local filesystems like ftp
44 if ($innerIterator->isRewindable()) {
45 $innerIterator->next();
46 $innerIterator->rewind();
48 } elseif ($innerIterator instanceof \FilesystemIterator) {
49 $innerIterator->next();
50 $innerIterator->rewind();
53 $iterator = $innerIterator;