Skip to content

Commit 7fb65db

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Finder] Fix recursive filter iterator Improve the structure of the Finder testsuite [VarDumper] Fix HtmlDumper constructor calling CliDumper's [Finder] Handle filtering of recursive iterators and use it to skip looping over excluded directories Exclude files based on path before applying the sorting fixed composer.json [Console] fix phpdoc of DialogHelper Allowed extensions to inline compiler passes
2 parents 142440d + 6d182a7 commit 7fb65db

13 files changed

+270
-308
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/ExcludeDirectoryFilterIterator.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
*
1717
* @author Fabien Potencier <[email protected]>
1818
*/
19-
class ExcludeDirectoryFilterIterator extends FilterIterator
19+
class ExcludeDirectoryFilterIterator extends FilterIterator implements \RecursiveIterator
2020
{
21+
private $isRecursive;
2122
private $patterns = array();
2223

2324
/**
@@ -28,6 +29,7 @@ class ExcludeDirectoryFilterIterator extends FilterIterator
2829
*/
2930
public function __construct(\Iterator $iterator, array $directories)
3031
{
32+
$this->isRecursive = $iterator instanceof \RecursiveIterator;
3133
foreach ($directories as $directory) {
3234
$this->patterns[] = '#(^|/)'.preg_quote($directory, '#').'(/|$)#';
3335
}
@@ -52,4 +54,17 @@ public function accept()
5254

5355
return true;
5456
}
57+
58+
public function hasChildren()
59+
{
60+
return $this->isRecursive && $this->getInnerIterator()->hasChildren();
61+
}
62+
63+
public function getChildren()
64+
{
65+
$children = new self($this->getInnerIterator()->getChildren(), array());
66+
$children->patterns = $this->patterns;
67+
68+
return $children;
69+
}
5570
}

Tests/BsdFinderTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Finder\Tests;
13+
14+
use Symfony\Component\Finder\Adapter\BsdFindAdapter;
15+
16+
class BsdFinderTest extends FinderTest
17+
{
18+
protected function getAdapter()
19+
{
20+
$adapter = new BsdFindAdapter();
21+
22+
if (!$adapter->isSupported()) {
23+
$this->markTestSkipped(get_class($adapter).' is not supported.');
24+
}
25+
26+
return $adapter;
27+
}
28+
}

0 commit comments

Comments
 (0)