Skip to content

Commit 6d182a7

Browse files
Merge branch '2.3' into 2.7
* 2.3: [Finder] Fix recursive filter iterator Improve the structure of the Finder testsuite Conflicts: src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php src/Symfony/Component/Finder/Tests/FinderTest.php src/Symfony/Component/Finder/Tests/Iterator/DateRangeFilterIteratorTest.php
2 parents 9aee8e2 + d6ad6ed commit 6d182a7

13 files changed

+260
-307
lines changed

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
}

Iterator/FilterIterator.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,8 @@
1818
*
1919
* @author Alex Bogomazov
2020
*/
21-
abstract class FilterIterator extends \FilterIterator implements \RecursiveIterator
21+
abstract class FilterIterator extends \FilterIterator
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-
3323
/**
3424
* This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after
3525
* rewind in some cases.

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)