Doctrine\MongoDB\Query\Query::prepareCursor PHP Method

prepareCursor() protected method

This method will apply cursor options present in the query structure array. The Cursor may also be wrapped with an EagerCursor.
protected prepareCursor ( Doctrine\MongoDB\Cursor $cursor ) : Doctrine\MongoDB\CursorInterface
$cursor Doctrine\MongoDB\Cursor
return Doctrine\MongoDB\CursorInterface
    protected function prepareCursor(Cursor $cursor)
    {
        /* Note: if this cursor resulted from a mapReduce command, applying the
         * read preference may be undesirable. Results would have been written
         * to the primary and replication may still be in progress.
         */
        if (isset($this->query['readPreference'])) {
            $cursor->setReadPreference($this->query['readPreference'], $this->query['readPreferenceTags']);
        }
        foreach ($this->getQueryOptions('hint', 'immortal', 'limit', 'maxTimeMS', 'skip', 'slaveOkay', 'sort') as $key => $value) {
            $cursor->{$key}($value);
        }
        if (!empty($this->query['snapshot'])) {
            $cursor->snapshot();
        }
        if (!empty($this->query['eagerCursor'])) {
            $cursor = new EagerCursor($cursor);
        }
        if (isset($this->query['useIdentifierKeys'])) {
            $cursor->setUseIdentifierKeys($this->query['useIdentifierKeys']);
        }
        return $cursor;
    }

Usage Example

Example #1
0
 /**
  * Prepare the Cursor returned by {@link Query::execute()}.
  *
  * This method will wrap the base Cursor with an ODM Cursor or EagerCursor,
  * and set the hydrate option and UnitOfWork hints. This occurs in addition
  * to any preparation done by the base Query class.
  *
  * @see \Doctrine\MongoDB\Cursor::prepareCursor()
  * @param BaseCursor $cursor
  * @return Cursor|EagerCursor
  */
 protected function prepareCursor(BaseCursor $cursor)
 {
     $cursor = parent::prepareCursor($cursor);
     // Unwrap a base EagerCursor
     if ($cursor instanceof BaseEagerCursor) {
         $cursor = $cursor->getCursor();
     }
     // Convert the base Cursor into an ODM Cursor
     $cursor = new Cursor($cursor, $this->dm->getUnitOfWork(), $this->class);
     // Wrap ODM Cursor with EagerCursor
     if (!empty($this->query['eagerCursor'])) {
         $cursor = new EagerCursor($cursor, $this->dm->getUnitOfWork(), $this->class);
     }
     $cursor->hydrate($this->hydrate);
     $cursor->setHints($this->unitOfWorkHints);
     return $cursor;
 }
All Usage Examples Of Doctrine\MongoDB\Query\Query::prepareCursor