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
This commit is contained in:
Fabien Potencier 2015-09-15 13:37:25 +02:00
commit c67e8b26b3
3 changed files with 23 additions and 14 deletions

View File

@ -399,7 +399,7 @@ class DialogHelper extends InputAwareHelper
/**
* Returns the helper's input stream.
*
* @return string
* @return resource|null The input stream or null if the default STDIN is used
*/
public function getInputStream()
{

View File

@ -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);
}
@ -68,15 +67,15 @@ class PhpAdapter extends AbstractAdapter
$iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
}
if ($this->paths || $this->notPaths) {
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
}
if ($this->sort) {
$iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
$iterator = $iteratorAggregate->getIterator();
}
if ($this->paths || $this->notPaths) {
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
}
return $iterator;
}

View File

@ -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.