merged branch pcampr/patch-1 (PR #3439)

Commits
-------

15910a0 fixed coding standards
24a3cd3 Finder - allow sorting when searching in multiple directories

Discussion
----------

[Finder] not searching in multiple dirs with sorting

I hit on a problem with **Finder, when using array of directories passed to ->in() together with sorting** (e.g. ->sortByName()):

*Catchable Fatal Error: Argument 1 passed to AppendIterator::append() must implement interface Iterator, instance of Symfony\Component\Finder\Iterator\SortableIterator given in ......\vendor\symfony\src\Symfony\Component\Finder\Finder.php line 421*

The problem is in Finder.php, line 419. When more than 1 directory is used, \AppendIterator is used to merge iterators for each directory. AppendIterator->append() accepts only objects implementing Iterator interface. But this is broken for SortableIterator, which implements IteratorAggregate and NOT Iterator.

My proposed solution retrieves an Iterator from IteratorAggregate, which is later valid as an input to AppendIterator->append()

(This solved the exception mentioned aboved in my testing project, not tested more.)
This commit is contained in:
Fabien Potencier 2012-02-24 11:34:01 +01:00
commit 3223f51bb1

View File

@ -502,7 +502,8 @@ class Finder implements \IteratorAggregate
}
if ($this->sort) {
$iterator = new Iterator\SortableIterator($iterator, $this->sort);
$iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
$iterator = $iteratorAggregate->getIterator();
}
return $iterator;