From fd22d8fa0353f9b7a92fb3b0f6b4a2d95eebfc5d Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Mon, 14 Sep 2015 17:16:40 +0200 Subject: [PATCH 1/3] [Console] fix phpdoc of DialogHelper --- src/Symfony/Component/Console/Helper/DialogHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Helper/DialogHelper.php b/src/Symfony/Component/Console/Helper/DialogHelper.php index adbf1869c0..fbb0f06623 100644 --- a/src/Symfony/Component/Console/Helper/DialogHelper.php +++ b/src/Symfony/Component/Console/Helper/DialogHelper.php @@ -385,7 +385,7 @@ class DialogHelper extends Helper /** * 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() { From e5bf0ab8770458e592c096c7ce24a5b270cf5b0b Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 15 Sep 2015 11:15:55 +0200 Subject: [PATCH 2/3] Exclude files based on path before applying the sorting Sorting can be slow, so it is best to applied it after all filtering rules are applied instead of using a bigger list and filtering again after that. --- src/Symfony/Component/Finder/Adapter/PhpAdapter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Finder/Adapter/PhpAdapter.php b/src/Symfony/Component/Finder/Adapter/PhpAdapter.php index 378a26acda..d8c32dbb4f 100644 --- a/src/Symfony/Component/Finder/Adapter/PhpAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/PhpAdapter.php @@ -68,15 +68,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; } From 8c691bd01fe0189df6a118059fe5330733e27930 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 15 Sep 2015 09:27:50 +0200 Subject: [PATCH 3/3] [Finder] Handle filtering of recursive iterators and use it to skip looping over excluded directories --- .../Component/Finder/Adapter/PhpAdapter.php | 15 +++++++-------- .../Component/Finder/Iterator/FilterIterator.php | 12 +++++++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Finder/Adapter/PhpAdapter.php b/src/Symfony/Component/Finder/Adapter/PhpAdapter.php index d8c32dbb4f..e8ada3671c 100644 --- a/src/Symfony/Component/Finder/Adapter/PhpAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/PhpAdapter.php @@ -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); } diff --git a/src/Symfony/Component/Finder/Iterator/FilterIterator.php b/src/Symfony/Component/Finder/Iterator/FilterIterator.php index f4da44c4cd..c5290cc80f 100644 --- a/src/Symfony/Component/Finder/Iterator/FilterIterator.php +++ b/src/Symfony/Component/Finder/Iterator/FilterIterator.php @@ -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.