serviceContainer = $serviceContainer; } if ($securityTokenStorage != null) { $this->securityTokenStorage = $securityTokenStorage; } if ($httpClient != null) { $this->httpClient = $httpClient; } $this->dataResponse = $dataResponse; } /** * @param string $url * @param string $method * @param array $data * @param int $timeout * * @return HttpResponse */ public function makeRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array(), $timeout = 60) { // $request = new HttpRequest($method, $url); // $headers = array(); // if (!empty($data)) { // $headers[] = 'Content-Type: application/x-www-form-urlencoded'; // $request->setContent(http_build_query($data)); // } // $request->setHeaders($headers); // $response = new HttpResponse(); // $this->httpClient->send($request, $response); // // return $response->getContent(); throw new Exception("Not implemented."); } /** * @param string $url * @param string $method * @param array $data * @param array $credentials * @param array $cookies * @param int $timeout * * @return HttpResponse */ public function makeGetRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array(), $credentials = array(), $cookies = array(), $timeout = 60) { $response = ''; foreach ((array)$this->dataResponse as $k => $v) { $key = null; if ($this->serviceContainer->hasParameter($k)) { $key = $this->serviceContainer->getParameter($k); } if (($key != null && strpos($url, $key) !== false) || strpos($url, $k) !== false) { $response = $v; break; } } return $response; } /** * @param string $webservice * @param int $id * @param array $data * * @return array */ public function putData($webservice, $id, $data) { // if ($this->serviceContainer->hasParameter($webservice)) { // $url = str_replace(".json", "/{$id}", $this->serviceContainer->getParameter($webservice)); // $data_string = json_encode($data); // // $ch = curl_init($url); // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); // curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); // curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // // try { // $return = curl_exec($ch); // } catch (\Exception $ex) { // return array("error" => "Connection Error."); // } // // if ($return) { // return json_decode($return, true); // } else { // return array("error" => "Transaction Error."); // } // } // return array("error" => "Webservice({$webservice}) not found."); throw new Exception("Not implemented."); } /** * @return array */ public function getDataResponse() { return $this->dataResponse; } /** * @param array $dataResponse */ public function setDataResponse($dataResponse) { $this->dataResponse = $dataResponse; } public function getData($url, $filters = array(), $order_by = array(), $limit = null, $offset = null) { if(isset($this->dataResponse[$url])){ return $this->dataResponse[$url]; }else{ return array(); } } }