Skip to content

Commit 9aee8e2

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [Finder] Handle filtering of recursive iterators and use it to skip looping over excluded directories Exclude files based on path before applying the sorting [Console] fix phpdoc of DialogHelper
2 parents fff4b0c + 23f16ce commit 9aee8e2

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

Adapter/PhpAdapter.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ public function searchInDirectory($dir)
3131
$flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
3232
}
3333

34-
$iterator = new \RecursiveIteratorIterator(
35-
new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs),
36-
\RecursiveIteratorIterator::SELF_FIRST
37-
);
34+
$iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
35+
36+
if ($this->exclude) {
37+
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
38+
}
39+
40+
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
3841

3942
if ($this->minDepth > 0 || $this->maxDepth < PHP_INT_MAX) {
4043
$iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
@@ -44,10 +47,6 @@ public function searchInDirectory($dir)
4447
$iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
4548
}
4649

47-
if ($this->exclude) {
48-
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
49-
}
50-
5150
if ($this->names || $this->notNames) {
5251
$iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
5352
}
@@ -68,15 +67,15 @@ public function searchInDirectory($dir)
6867
$iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
6968
}
7069

70+
if ($this->paths || $this->notPaths) {
71+
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
72+
}
73+
7174
if ($this->sort) {
7275
$iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
7376
$iterator = $iteratorAggregate->getIterator();
7477
}
7578

76-
if ($this->paths || $this->notPaths) {
77-
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
78-
}
79-
8079
return $iterator;
8180
}
8281

Iterator/FilterIterator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@
1818
*
1919
* @author Alex Bogomazov
2020
*/
21-
abstract class FilterIterator extends \FilterIterator
21+
abstract class FilterIterator extends \FilterIterator implements \RecursiveIterator
2222
{
23+
public function hasChildren()
24+
{
25+
return $this->getInnerIterator() instanceof \RecursiveIterator && $this->getInnerIterator()->hasChildren();
26+
}
27+
28+
public function getChildren()
29+
{
30+
return $this->getInnerIterator()->getChildren();
31+
}
32+
2333
/**
2434
* This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after
2535
* rewind in some cases.

0 commit comments

Comments
 (0)