/** * @param string $method * @param string $action * @param mixed $data * * @return mixed * @throws QuarkArchException */ private function _api($method, $action, $data = []) { $request = new QuarkDTO(new QuarkJSONIOProcessor()); $request->Method($method); $request->Merge($data); $response = new QuarkDTO(new QuarkJSONIOProcessor()); if (!$this->_uri) { throw new QuarkArchException('QuarkRest API is not reachable. URI is not provided'); } $this->_uri->path = $action; $data = QuarkHTTPTransportClient::To($this->_uri->URI(true), $request, $response); if ($data == null || !isset($data->status) || $data->status != 200) { throw new QuarkArchException('QuarkRest API is not reachable. Response: ' . print_r($data, true)); } return $data; }
/** * @param QuarkURI $uri * * @return mixed * * @throws QuarkConnectionException */ public function Connect(QuarkURI $uri) { try { $options = array(); if (is_array($uri->options)) { $options = $uri->options; } $this->_connection = new \MongoClient($uri->URI(), $options); $uri->path = str_replace('/', '', $uri->path); if (strlen(trim($uri->path)) != 0) { $db = $uri->path; $this->_connection = $this->_connection->{$db}; } } catch (\Exception $e) { throw new QuarkConnectionException($uri, Quark::LOG_FATAL); } }