Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Finder] not searching in multiple dirs with sorting #3439

Merged
merged 2 commits into from Feb 24, 2012
Merged

[Finder] not searching in multiple dirs with sorting #3439

merged 2 commits into from Feb 24, 2012

Conversation

pcampr
Copy link
Contributor

@pcampr pcampr commented Feb 24, 2012

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

@@ -502,7 +502,8 @@ private function searchInDirectory($dir)
}

if ($this->sort) {
$iterator = new Iterator\SortableIterator($iterator, $this->sort);
$iterator_aggregate = new Iterator\SortableIterator($iterator, $this->sort);
$iterator = $iterator_aggregate->getIterator();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coding standards are to use camel cased names for variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coding standards fixed

fabpot added a commit that referenced this pull request Feb 24, 2012
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.)
@fabpot fabpot merged commit 15910a0 into symfony:2.0 Feb 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants