[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;
|
||||
}
|
||||
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs),
|
||||
\RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
$iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
|
||||
|
||||
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) {
|
||||
$iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
|
||||
@ -44,10 +47,6 @@ class PhpAdapter extends AbstractAdapter
|
||||
$iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
|
||||
}
|
||||
|
||||
if ($this->exclude) {
|
||||
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
|
||||
}
|
||||
|
||||
if ($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
|
||||
*/
|
||||
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
|
||||
* rewind in some cases.
|
||||
|
Reference in New Issue
Block a user