serviceContainer = $serviceContainer; if($this->serviceContainer->getParameter("endpoint.mongodb.connection")) { $this->location = $this->serviceContainer->getParameter("endpoint.mongodb.connection"); } else { $this->location = null; } } /** * @param string $json * @param string $query * query = [last|query|search] */ public function get($json, $method = "query", $exception = false) { if(is_null($this->location)) return array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "{$this->location}/{$method}"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_POST, 1); $headers = array(); $headers[] = "Content-Type: application/json"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { if($exception) { curl_close($ch); throw new Exception(curl_error($ch)); } else { echo 'Error:' . curl_error($ch); } } curl_close($ch); $data = json_decode($result,true); if(is_array($data)) return $data; return array(); } }