[Finder] Check PHP version before applying a workaround for a PHP bug
This commit is contained in:
parent
5d63c554e8
commit
cba206ab18
@ -12,9 +12,10 @@
|
||||
namespace Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* This iterator just overrides the rewind method in order to correct a PHP bug.
|
||||
* This iterator just overrides the rewind method in order to correct a PHP bug,
|
||||
* which existed before version 5.5.23/5.6.7.
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=49104
|
||||
* @see https://bugs.php.net/68557
|
||||
*
|
||||
* @author Alex Bogomazov
|
||||
*/
|
||||
@ -28,18 +29,19 @@ abstract class FilterIterator extends \FilterIterator
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
if (PHP_VERSION_ID > 50607 || (PHP_VERSION_ID > 50523 && PHP_VERSION_ID < 50600)) {
|
||||
parent::rewind();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$iterator = $this;
|
||||
while ($iterator instanceof \OuterIterator) {
|
||||
$innerIterator = $iterator->getInnerIterator();
|
||||
|
||||
if ($innerIterator instanceof RecursiveDirectoryIterator) {
|
||||
if ($innerIterator->isRewindable()) {
|
||||
$innerIterator->next();
|
||||
$innerIterator->rewind();
|
||||
}
|
||||
} elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
|
||||
$iterator->getInnerIterator()->next();
|
||||
$iterator->getInnerIterator()->rewind();
|
||||
if ($innerIterator instanceof \FilesystemIterator) {
|
||||
$innerIterator->next();
|
||||
$innerIterator->rewind();
|
||||
}
|
||||
$iterator = $iterator->getInnerIterator();
|
||||
}
|
||||
|
@ -118,8 +118,10 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
return;
|
||||
}
|
||||
|
||||
// @see https://bugs.php.net/bug.php?id=49104
|
||||
parent::next();
|
||||
// @see https://bugs.php.net/68557
|
||||
if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) {
|
||||
parent::next();
|
||||
}
|
||||
|
||||
parent::rewind();
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
* Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
|
||||
* with inner FilesystemIterator in an invalid state.
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=49104
|
||||
* @see https://bugs.php.net/68557
|
||||
*/
|
||||
public function testMultipleLocations()
|
||||
{
|
||||
@ -468,8 +468,12 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
);
|
||||
|
||||
// it is expected that there are test.py test.php in the tmpDir
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in($locations)->depth('< 1')->name('test.php');
|
||||
$finder = new Finder();
|
||||
$finder->in($locations)
|
||||
// the default flag IGNORE_DOT_FILES fixes the problem indirectly
|
||||
// so we set it to false for better isolation
|
||||
->ignoreDotFiles(false)
|
||||
->depth('< 1')->name('test.php');
|
||||
|
||||
$this->assertCount(1, $finder);
|
||||
}
|
||||
@ -479,7 +483,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
* AppendIterator which does an unnecessary rewind which leaves
|
||||
* FilterIterator with inner FilesystemIterator in an invalid state.
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=49104
|
||||
* @see https://bugs.php.net/68557
|
||||
*/
|
||||
public function testMultipleLocationsWithSubDirectories()
|
||||
{
|
||||
|
@ -43,8 +43,9 @@ class FilterIteratorTest extends RealIteratorTestCase
|
||||
++$c;
|
||||
}
|
||||
|
||||
// This would fail with \FilterIterator but works with Symfony\Component\Finder\Iterator\FilterIterator
|
||||
// see https://bugs.php.net/bug.php?id=49104
|
||||
// This would fail in php older than 5.5.23/5.6.7 with \FilterIterator
|
||||
// but works with Symfony\Component\Finder\Iterator\FilterIterator
|
||||
// see https://bugs.php.net/68557
|
||||
$this->assertEquals(1, $c);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user