/**
  * Thrown when a file cannot be found by its ID.
  *
  * @param mixed  $id        File ID
  * @param string $namespace Namespace for the files collection
  * @return self
  */
 public static function byId($id, $namespace)
 {
     $json = \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP(['_id' => $id]));
     return new static(sprintf('File "%s" not found in "%s"', $json, $namespace));
 }
Ejemplo n.º 2
0
 /**
  * Creates a path for an existing GridFS file.
  *
  * @param stdClass $file GridFS file document
  * @return string
  */
 private function createPathForFile(stdClass $file)
 {
     if (!is_object($file->_id) || method_exists($file->_id, '__toString')) {
         $id = (string) $file->_id;
     } else {
         $id = \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP(['_id' => $file->_id]));
     }
     return sprintf('%s://%s/%s.files/%s', self::$streamWrapperProtocol, urlencode($this->databaseName), urlencode($this->options['bucketName']), urlencode($id));
 }
Ejemplo n.º 3
0
 /**
  * 查
  * @return mixed
  */
 public function get()
 {
     try {
         $filter = (array) $this->wheres;
         $options = ['projection' => (array) $this->selects, "sort" => (array) $this->sorts, "skip" => (int) $this->offset, "limit" => (int) $this->limit];
         $query = new \MongoDB\Driver\Query($filter, $options);
         $dbc = $this->database . '.' . $this->collection;
         $documents = $this->manager->executeQuery($dbc, $query);
         $this->result = $documents;
         $returns = array();
         foreach ($documents as $document) {
             $bson = \MongoDB\BSON\fromPHP($document);
             $returns[] = json_decode(\MongoDB\BSON\toJSON($bson), true);
         }
         return $returns;
     } catch (\Exception $e) {
         $this->showError($e);
     }
 }