/** * 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)); }
/** * Serializes a PHP variable into a BSON string * * @param mixed $anything The variable to be serialized. * @return string Returns the serialized string. */ function bson_encode($anything) { return \MongoDB\BSON\fromPHP(TypeConverter::fromLegacy($anything)); }
/** * 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)); }
/** * 查 * @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); } }