Пример #1
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;
 }
Пример #2
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;
 }