Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b067fa2

Browse files
committed
[Finder] Check PHP version before applying a workaround for a pre PHP
5.5.23/5.6.7 bug.
1 parent 45a0060 commit b067fa2

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/Symfony/Component/Finder/Iterator/FilterIterator.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\Finder\Iterator;
1313

1414
/**
15-
* This iterator just overrides the rewind method in order to correct a PHP bug.
15+
* This iterator just overrides the rewind method in order to correct a PHP bug, which existed before version 5.5.23.
1616
*
17-
* @see https://bugs.php.net/bug.php?id=49104
17+
* @see https://bugs.php.net/bug.php?id=68557
1818
*
1919
* @author Alex Bogomazov
2020
*/
@@ -28,22 +28,24 @@ abstract class FilterIterator extends \FilterIterator
2828
*/
2929
public function rewind()
3030
{
31-
$iterator = $this;
32-
while ($iterator instanceof \OuterIterator) {
33-
$innerIterator = $iterator->getInnerIterator();
31+
if (version_compare(PHP_VERSION, '5.5.23', '<')
32+
or (version_compare(PHP_VERSION, '5.6.0', '>=') and version_compare(PHP_VERSION, '5.6.7', '<'))) {
33+
$iterator = $this;
34+
while ($iterator instanceof \OuterIterator) {
35+
$innerIterator = $iterator->getInnerIterator();
3436

35-
if ($innerIterator instanceof RecursiveDirectoryIterator) {
36-
if ($innerIterator->isRewindable()) {
37-
$innerIterator->next();
38-
$innerIterator->rewind();
37+
if ($innerIterator instanceof RecursiveDirectoryIterator) {
38+
if ($innerIterator->isRewindable()) {
39+
$innerIterator->next();
40+
$innerIterator->rewind();
41+
}
42+
} elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
43+
$iterator->getInnerIterator()->next();
44+
$iterator->getInnerIterator()->rewind();
3945
}
40-
} elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
41-
$iterator->getInnerIterator()->next();
42-
$iterator->getInnerIterator()->rewind();
46+
$iterator = $iterator->getInnerIterator();
4347
}
44-
$iterator = $iterator->getInnerIterator();
4548
}
46-
4749
parent::rewind();
4850
}
4951
}

src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ public function rewind()
118118
return;
119119
}
120120

121-
// @see https://bugs.php.net/bug.php?id=49104
122-
parent::next();
121+
// @see https://bugs.php.net/bug.php?id=68557
122+
if (version_compare(PHP_VERSION, '5.5.23', '<')
123+
or (version_compare(PHP_VERSION, '5.6.0', '>=') and version_compare(PHP_VERSION, '5.6.7', '<'))) {
124+
parent::next();
125+
}
123126

124127
parent::rewind();
125128
}

src/Symfony/Component/Finder/Tests/Iterator/FilterIteratorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ public function testFilterFilesystemIterators()
4343
++$c;
4444
}
4545

46-
// This would fail with \FilterIterator but works with Symfony\Component\Finder\Iterator\FilterIterator
47-
// see https://bugs.php.net/bug.php?id=49104
46+
// This would fail in php older than 5.5.23/5.6.7 with \FilterIterator
47+
// but works with Symfony\Component\Finder\Iterator\FilterIterator
48+
// see https://bugs.php.net/bug.php?id=68557
4849
$this->assertEquals(1, $c);
4950
}
5051
}

0 commit comments

Comments
 (0)