minor #17134 [Finder] Check PHP version before applying a workaround for a PHP bug (alebo)
This PR was squashed before being merged into the 2.3 branch (closes #17134).
Discussion
----------
[Finder] Check PHP version before applying a workaround for a PHP bug
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | --
| License | MIT
| Doc PR | --
Commits
-------
cba206a
[Finder] Check PHP version before applying a workaround for a PHP bug
This commit is contained in:
commit
414365d8ef
@ -12,9 +12,10 @@
|
|||||||
namespace Symfony\Component\Finder\Iterator;
|
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
|
* @author Alex Bogomazov
|
||||||
*/
|
*/
|
||||||
@ -28,18 +29,19 @@ abstract class FilterIterator extends \FilterIterator
|
|||||||
*/
|
*/
|
||||||
public function rewind()
|
public function rewind()
|
||||||
{
|
{
|
||||||
|
if (PHP_VERSION_ID > 50607 || (PHP_VERSION_ID > 50523 && PHP_VERSION_ID < 50600)) {
|
||||||
|
parent::rewind();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$iterator = $this;
|
$iterator = $this;
|
||||||
while ($iterator instanceof \OuterIterator) {
|
while ($iterator instanceof \OuterIterator) {
|
||||||
$innerIterator = $iterator->getInnerIterator();
|
$innerIterator = $iterator->getInnerIterator();
|
||||||
|
|
||||||
if ($innerIterator instanceof RecursiveDirectoryIterator) {
|
if ($innerIterator instanceof \FilesystemIterator) {
|
||||||
if ($innerIterator->isRewindable()) {
|
$innerIterator->next();
|
||||||
$innerIterator->next();
|
$innerIterator->rewind();
|
||||||
$innerIterator->rewind();
|
|
||||||
}
|
|
||||||
} elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
|
|
||||||
$iterator->getInnerIterator()->next();
|
|
||||||
$iterator->getInnerIterator()->rewind();
|
|
||||||
}
|
}
|
||||||
$iterator = $iterator->getInnerIterator();
|
$iterator = $iterator->getInnerIterator();
|
||||||
}
|
}
|
||||||
|
@ -118,8 +118,10 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @see https://bugs.php.net/bug.php?id=49104
|
// @see https://bugs.php.net/68557
|
||||||
parent::next();
|
if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) {
|
||||||
|
parent::next();
|
||||||
|
}
|
||||||
|
|
||||||
parent::rewind();
|
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
|
* Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
|
||||||
* with inner FilesystemIterator in an invalid state.
|
* 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()
|
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
|
// it is expected that there are test.py test.php in the tmpDir
|
||||||
$finder = $this->buildFinder();
|
$finder = new Finder();
|
||||||
$finder->in($locations)->depth('< 1')->name('test.php');
|
$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);
|
$this->assertCount(1, $finder);
|
||||||
}
|
}
|
||||||
@ -479,7 +483,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
|||||||
* AppendIterator which does an unnecessary rewind which leaves
|
* AppendIterator which does an unnecessary rewind which leaves
|
||||||
* FilterIterator with inner FilesystemIterator in an invalid state.
|
* 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()
|
public function testMultipleLocationsWithSubDirectories()
|
||||||
{
|
{
|
||||||
|
@ -43,8 +43,9 @@ class FilterIteratorTest extends RealIteratorTestCase
|
|||||||
++$c;
|
++$c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This would fail with \FilterIterator but works with Symfony\Component\Finder\Iterator\FilterIterator
|
// This would fail in php older than 5.5.23/5.6.7 with \FilterIterator
|
||||||
// see https://bugs.php.net/bug.php?id=49104
|
// but works with Symfony\Component\Finder\Iterator\FilterIterator
|
||||||
|
// see https://bugs.php.net/68557
|
||||||
$this->assertEquals(1, $c);
|
$this->assertEquals(1, $c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user