Skip to content

Commit de24c81

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 de24c81

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
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,
16+
* which existed before version 5.5.23/5.6.7.
1617
*
17-
* @see https://bugs.php.net/bug.php?id=49104
18+
* @see https://bugs.php.net/bug.php?id=68557
1819
*
1920
* @author Alex Bogomazov
2021
*/
@@ -28,22 +29,24 @@ abstract class FilterIterator extends \FilterIterator
2829
*/
2930
public function rewind()
3031
{
31-
$iterator = $this;
32-
while ($iterator instanceof \OuterIterator) {
33-
$innerIterator = $iterator->getInnerIterator();
32+
if (version_compare(PHP_VERSION, '5.5.23', '<')
33+
or (version_compare(PHP_VERSION, '5.6.0', '>=') and version_compare(PHP_VERSION, '5.6.7', '<'))) {
34+
$iterator = $this;
35+
while ($iterator instanceof \OuterIterator) {
36+
$innerIterator = $iterator->getInnerIterator();
3437

35-
if ($innerIterator instanceof RecursiveDirectoryIterator) {
36-
if ($innerIterator->isRewindable()) {
37-
$innerIterator->next();
38-
$innerIterator->rewind();
38+
if ($innerIterator instanceof RecursiveDirectoryIterator) {
39+
if ($innerIterator->isRewindable()) {
40+
$innerIterator->next();
41+
$innerIterator->rewind();
42+
}
43+
} elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
44+
$iterator->getInnerIterator()->next();
45+
$iterator->getInnerIterator()->rewind();
3946
}
40-
} elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
41-
$iterator->getInnerIterator()->next();
42-
$iterator->getInnerIterator()->rewind();
47+
$iterator = $iterator->getInnerIterator();
4348
}
44-
$iterator = $iterator->getInnerIterator();
4549
}
46-
4750
parent::rewind();
4851
}
4952
}

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy