Ejemplo n.º 1
0
 /**
  * @param \MongoGridFSCursor $cursor Mongo cursor instance to fetch data from.
  * @param boolean $all whether to fetch all rows or only first one.
  * @param string|callable $indexBy value to index by.
  * @return array|boolean result.
  * @see Query::fetchRows()
  */
 protected function fetchRowsInternal($cursor, $all, $indexBy)
 {
     $result = [];
     if ($all) {
         foreach ($cursor as $file) {
             $row = $file->file;
             $row['file'] = $file;
             if ($indexBy !== null) {
                 if (is_string($indexBy)) {
                     $key = $row[$indexBy];
                 } else {
                     $key = call_user_func($indexBy, $row);
                 }
                 $result[$key] = $row;
             } else {
                 $result[] = $row;
             }
         }
     } else {
         if ($cursor->hasNext()) {
             $file = $cursor->getNext();
             $result = $file->file;
             $result['file'] = $file;
         } else {
             $result = false;
         }
     }
     return $result;
 }
 public function hasNext()
 {
     $this->logQuery();
     return parent::hasNext();
 }