Skip to content

Commit

Permalink
Merge pull request doctrine#2579 from alcaeus/use-cursor-interface
Browse files Browse the repository at this point in the history
Aggregation uses CursorInterface instead of Cursor
  • Loading branch information
malarzm authored Nov 8, 2023
2 parents aadcca0 + d1df723 commit 22f4086
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
use Doctrine\ODM\MongoDB\Iterator\Iterator;
use Doctrine\ODM\MongoDB\Iterator\UnrewindableIterator;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Iterator as SPLIterator;
use IteratorAggregate;
use MongoDB\Collection;
use MongoDB\Driver\Cursor;
use MongoDB\Driver\CursorInterface;

use function array_merge;
use function assert;
Expand All @@ -35,12 +36,14 @@ public function getIterator(): Iterator
$options = array_merge($this->options, ['cursor' => true]);

$cursor = $this->collection->aggregate($this->pipeline, $options);
assert($cursor instanceof Cursor);
// This assertion can be dropped when requiring mongodb/mongodb 1.17.0
assert($cursor instanceof CursorInterface);
assert($cursor instanceof SPLIterator);

return $this->prepareIterator($cursor);
}

private function prepareIterator(Cursor $cursor): Iterator
private function prepareIterator(CursorInterface&SPLIterator $cursor): Iterator
{
if ($this->classMetadata) {
$cursor = new HydratingIterator($cursor, $this->dm->getUnitOfWork(), $this->classMetadata);
Expand Down

0 comments on commit 22f4086

Please sign in to comment.