[Finder] Handle filtering of recursive iterators and use it to skip looping over excluded directories
This commit is contained in:
parent
306d88a1e3
commit
8c691bd01f
@ -31,10 +31,13 @@ class PhpAdapter extends AbstractAdapter
|
|||||||
$flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
|
$flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
|
||||||
new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs),
|
|
||||||
\RecursiveIteratorIterator::SELF_FIRST
|
if ($this->exclude) {
|
||||||
);
|
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
|
||||||
|
}
|
||||||
|
|
||||||
|
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
|
||||||
|
|
||||||
if ($this->minDepth > 0 || $this->maxDepth < PHP_INT_MAX) {
|
if ($this->minDepth > 0 || $this->maxDepth < PHP_INT_MAX) {
|
||||||
$iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
|
$iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
|
||||||
@ -44,10 +47,6 @@ class PhpAdapter extends AbstractAdapter
|
|||||||
$iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
|
$iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->exclude) {
|
|
||||||
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->names || $this->notNames) {
|
if ($this->names || $this->notNames) {
|
||||||
$iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
|
$iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,18 @@ namespace Symfony\Component\Finder\Iterator;
|
|||||||
*
|
*
|
||||||
* @author Alex Bogomazov
|
* @author Alex Bogomazov
|
||||||
*/
|
*/
|
||||||
abstract class FilterIterator extends \FilterIterator
|
abstract class FilterIterator extends \FilterIterator implements \RecursiveIterator
|
||||||
{
|
{
|
||||||
|
public function hasChildren()
|
||||||
|
{
|
||||||
|
return $this->getInnerIterator() instanceof \RecursiveIterator && $this->getInnerIterator()->hasChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChildren()
|
||||||
|
{
|
||||||
|
return $this->getInnerIterator()->getChildren();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after
|
* This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after
|
||||||
* rewind in some cases.
|
* rewind in some cases.
|
||||||
|
Reference in New Issue
Block a user