hydrate() public method

public hydrate ( $bool )
    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;
    }
Beispiel #2
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;
 }
Beispiel #3
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;
 }
 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;
 }