|
|
@@ -52,7 +52,7 @@ abstract class AbstractCursor
|
|
|
protected $db;
|
|
|
|
|
|
/**
|
|
|
- * @var \Iterator
|
|
|
+ * @var CursorIterator
|
|
|
*/
|
|
|
protected $iterator;
|
|
|
|
|
|
@@ -131,11 +131,6 @@ abstract class AbstractCursor
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function __destruct()
|
|
|
- {
|
|
|
- $this->iterator = null;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Returns the current element
|
|
|
* @link http://www.php.net/manual/en/mongocursor.current.php
|
|
|
@@ -297,9 +292,8 @@ abstract class AbstractCursor
|
|
|
protected function ensureIterator()
|
|
|
{
|
|
|
if ($this->iterator === null) {
|
|
|
- // MongoDB\Driver\Cursor needs to be wrapped into a \Generator so that a valid \Iterator with working implementations of
|
|
|
- // next, current, valid, key and rewind is returned. These methods don't work if we wrap the Cursor inside an \IteratorIterator
|
|
|
$this->iterator = $this->wrapTraversable($this->ensureCursor());
|
|
|
+ $this->iterator->rewind();
|
|
|
}
|
|
|
|
|
|
return $this->iterator;
|
|
|
@@ -307,13 +301,11 @@ abstract class AbstractCursor
|
|
|
|
|
|
/**
|
|
|
* @param \Traversable $traversable
|
|
|
- * @return \Generator
|
|
|
+ * @return CursorIterator
|
|
|
*/
|
|
|
protected function wrapTraversable(\Traversable $traversable)
|
|
|
{
|
|
|
- foreach ($traversable as $key => $value) {
|
|
|
- yield $key => $value;
|
|
|
- }
|
|
|
+ return new CursorIterator($traversable);
|
|
|
}
|
|
|
|
|
|
/**
|