This class composes a Doctrine\MongoDB\Cursor instance and wraps its methods in order to return results as hydrated document class instances. Hydration behavior may be controlled with the {@link Cursor::hydrate()} method. For compatibility, this class also extends Doctrine\MongoDB\Cursor.
Since: 1.0
Inheritance: implements Doctrine\MongoDB\CursorInterface
Ejemplo n.º 1
0
    public function execute(array $options = array())
    {
        $uow = $this->dm->getUnitOfWork();

        $results = $this->query->execute($options);

        // Convert the regular mongodb cursor to the odm cursor
        if ($results instanceof BaseCursor) {
            $cursor = $results->getMongoCursor();
            $results = new Cursor($cursor, $this->dm->getUnitOfWork(), $this->class);
            $results->hydrate($this->hydrate);
        }

        // GeoLocationFindQuery just returns an instance of ArrayIterator so we have to
        // iterator over it and hydrate each object.
        if ($this->query instanceof \Doctrine\MongoDB\Query\GeoLocationFindQuery && $this->hydrate) {
            foreach ($results as $key => $result) {
                $document = $result['obj'];
                if ($this->class->distance) {
                    $document[$this->class->distance] = $result['dis'];
                }
                $results[$key] = $uow->getOrCreateDocument($this->class->name, $document);
            }
            $results->reset();
        }

        if ($this->hydrate && ($this->query instanceof FindAndRemoveQuery || $this->query instanceof FindAndUpdateQuery) && is_array($results) && isset($results['_id'])) {
            // Convert a single document array to a document object
            $results = $uow->getOrCreateDocument($this->class->name, $results);
        }

        return $results;
    }
 /**
  * {@inheritDoc}
  */
 public function count()
 {
     // Avoid using EagerCursor::count as this stores a collection without limits to memory
     if ($this->cursor->getBaseCursor() instanceof EagerCursor) {
         return $this->cursor->getBaseCursor()->getCursor()->count();
     }
     return $this->cursor->count();
 }
Ejemplo n.º 3
0
 /**
  * Give a cursor and create it if necessary
  *
  * @return CursorMongoDB
  */
 protected function getCursor()
 {
     if (null === $this->cursor) {
         $this->cursor = $this->queryBuilder->getQuery()->execute();
         if (null !== $this->batchSize) {
             $this->cursor->batchSize($this->batchSize);
         }
         // MongoDB Cursor are not positioned on first element (whereas ArrayIterator is)
         // as long as getNext() hasn't be called
         $this->cursor->getNext();
     }
     return $this->cursor;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function getItems($offset, $itemCountPerPage)
 {
     return $this->cursor->skip($offset)->limit($itemCountPerPage)->toArray();
 }
Ejemplo n.º 5
0
 private function wrapCursor(BaseCursor $baseCursor, array $hints)
 {
     if ($baseCursor instanceof BaseLoggableCursor) {
         $cursor = new LoggableCursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $baseCursor, $baseCursor->getQuery(), $baseCursor->getFields(), $this->dm->getConfiguration()->getRetryQuery(), $baseCursor->getLoggerCallable());
     } else {
         $cursor = new Cursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $baseCursor, $baseCursor->getQuery(), $baseCursor->getFields(), $this->dm->getConfiguration()->getRetryQuery());
     }
     $cursor->hydrate($this->hydrate);
     $cursor->setHints($hints);
     return $cursor;
 }
Ejemplo n.º 6
0
 /**
  * Execute the query and returns the results.
  *
  * @return mixed
  */
 public function execute()
 {
     $uow = $this->dm->getUnitOfWork();
     $results = parent::execute();
     // Convert the regular mongodb cursor to the odm cursor
     if ($results instanceof BaseCursor) {
         $cursor = $results->getMongoCursor();
         $results = new Cursor($cursor, $this->dm->getUnitOfWork(), $this->class);
         $results->hydrate($this->hydrate);
         $results->refresh($this->refresh);
     }
     $hints = array();
     if ($this->refresh) {
         $hints[self::HINT_REFRESH] = true;
     }
     // GeoLocationFindQuery just returns an instance of ArrayIterator so we have to
     // iterator over it and hydrate each object.
     if ($this->query['type'] === self::TYPE_GEO_LOCATION && $this->hydrate) {
         foreach ($results as $key => $result) {
             $document = $result['obj'];
             if ($this->class->distance) {
                 $document[$this->class->distance] = $result['dis'];
             }
             $results[$key] = $uow->getOrCreateDocument($this->class->name, $document, $hints);
         }
         $results->reset();
     }
     if ($this->hydrate && is_array($results) && isset($results['_id'])) {
         // Convert a single document array to a document object
         $results = $uow->getOrCreateDocument($this->class->name, $results, $hints);
     }
     return $results;
 }
 /** @proxy */
 public function sort($fields)
 {
     $this->log(array('sort' => true, 'sortFields' => $fields));
     return parent::sort($fields);
 }
Ejemplo n.º 8
0
 private function wrapCursor(BaseCursor $baseCursor)
 {
     $mongoCursor = $baseCursor->getMongoCursor();
     if ($baseCursor instanceof BaseLoggableCursor) {
         $cursor = new LoggableCursor($mongoCursor, $this->dm->getUnitOfWork(), $this->class, $baseCursor->getLoggerCallable(), $baseCursor->getQuery(), $baseCursor->getFields());
     } else {
         $cursor = new Cursor($mongoCursor, $this->dm->getUnitOfWork(), $this->class);
     }
     $cursor->hydrate($this->hydrate);
     $cursor->refresh($this->refresh);
     return $cursor;
 }
 /**
  * {@inheritDoc}
  */
 public function count()
 {
     return $this->cursor->count();
 }
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     return new \ArrayIterator($this->cursor->toArray());
 }