Esempio n. 1
0
 /**
  * @inherit
  */
 public function makeRequest($method, $path, $data = array())
 {
     $url = $this->getEndpoint() . $path;
     $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array('Accept: application/json', 'Content-type: application/json', 'User-Agent: ' . Version::userAgent()), CURLOPT_CUSTOMREQUEST => self::GET, CURLOPT_POST => false, CURLOPT_POSTFIELDS => null);
     if ($this->username && $this->password) {
         $options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
         $options[CURLOPT_USERPWD] = $this->username . ':' . $this->password;
     }
     switch ($method) {
         case self::DELETE:
             $options[CURLOPT_CUSTOMREQUEST] = self::DELETE;
             break;
         case self::POST:
         case self::PUT:
             $dataString = $this->encodeData($data);
             $options[CURLOPT_CUSTOMREQUEST] = $method;
             $options[CURLOPT_POSTFIELDS] = $dataString;
             $options[CURLOPT_HTTPHEADER][] = 'Content-Length: ' . strlen($dataString);
             if (self::POST == $method) {
                 $options[CURLOPT_POST] = true;
             }
             break;
     }
     //additional curl options
     if (\Everyman\Neo4j\DI::isRegistered("curlOptions")) {
         $additionalOptions = \Everyman\Neo4j\DI::resolve("curlOptions");
         if (is_array($additionalOptions)) {
             $options = array_replace($options, $additionalOptions);
         }
         unset($additionalOptions);
     }
     $ch = $this->getHandle();
     curl_setopt_array($ch, $options);
     $response = curl_exec($ch);
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     if (!$code) {
         $code = 500;
         $headerSize = 0;
         $response = json_encode(array("error" => curl_error($ch) . ' [' . curl_errno($ch) . ']'));
     }
     $bodyString = substr($response, $headerSize);
     $bodyData = json_decode($bodyString, true);
     $headerString = substr($response, 0, $headerSize);
     $headers = explode("\r\n", $headerString);
     foreach ($headers as $i => $header) {
         unset($headers[$i]);
         $parts = explode(':', $header);
         if (isset($parts[1])) {
             $name = trim(array_shift($parts));
             $value = join(':', $parts);
             $headers[$name] = $value;
         }
     }
     return array('code' => $code, 'headers' => $headers, 'data' => $bodyData);
 }
 /**
  * @inherit
  */
 public function makeRequest($method, $path, $data = array())
 {
     $url = $this->getEndpoint() . $path;
     $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array('Accept: application/json;stream=true', 'Content-type: application/json', 'User-Agent: ' . Version::userAgent(), 'X-Stream: true'), CURLOPT_CUSTOMREQUEST => self::GET, CURLOPT_POST => false, CURLOPT_POSTFIELDS => null, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0);
     if ($this->username && $this->password) {
         $options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
         $options[CURLOPT_USERPWD] = $this->username . ':' . $this->password;
     }
     switch ($method) {
         case self::DELETE:
             $options[CURLOPT_CUSTOMREQUEST] = self::DELETE;
             break;
         case self::POST:
         case self::PUT:
             $dataString = $this->encodeData($data);
             $options[CURLOPT_CUSTOMREQUEST] = $method;
             $options[CURLOPT_POSTFIELDS] = $dataString;
             $options[CURLOPT_HTTPHEADER][] = 'Content-Length: ' . strlen($dataString);
             if (self::POST == $method) {
                 $options[CURLOPT_POST] = true;
             }
             break;
     }
     $ch = $this->getHandle();
     curl_setopt_array($ch, $options);
     $response = curl_exec($ch);
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     if ($response === false) {
         throw new Exception("Can't open connection to " . $url);
     }
     if (!$code) {
         $code = 500;
         $headerSize = 0;
         $response = json_encode(array("error" => curl_error($ch) . ' [' . curl_errno($ch) . ']'));
     }
     $bodyString = substr($response, $headerSize);
     $bodyData = json_decode($bodyString, true);
     $headerString = substr($response, 0, $headerSize);
     $headers = explode("\r\n", $headerString);
     foreach ($headers as $i => $header) {
         unset($headers[$i]);
         $parts = explode(':', $header);
         if (isset($parts[1])) {
             $name = trim(array_shift($parts));
             $value = join(':', $parts);
             $headers[$name] = $value;
         }
     }
     return array('code' => $code, 'headers' => $headers, 'data' => $bodyData);
 }
Esempio n. 3
0
 /**
  * @inherit
  */
 public function makeRequest($method, $path, $data = array())
 {
     $url = $this->getEndpoint() . $path;
     $context_options = array('http' => array('method' => 'GET', 'ignore_errors' => true, 'header' => "Content-type: application/json\r\n" . "Accept: application/json\r\n" . "User-Agent: " . Version::userAgent() . "\r\n"));
     if ($this->username && $this->password) {
         $context_options[$this->scheme]['header'] .= 'Authorization: Basic ' . base64_encode($this->username . ':' . $this->password) . "\r\n";
     }
     switch ($method) {
         case self::DELETE:
             $context_options[$this->scheme]['method'] = self::DELETE;
             break;
         case self::POST:
         case self::PUT:
             $dataString = $this->encodeData($data);
             $context_options['http']['method'] = $method;
             $context_options['http']['content'] = $dataString;
             $context_options['http']['header'] .= 'Context-Length: ' . strlen($dataString) . "\r\n";
             break;
     }
     //add options for the ssl connection
     if (\Everyman\Neo4j\DI::isRegistered("httpStreamOptions")) {
         $streamOptions = \Everyman\Neo4j\DI::resolve("httpStreamOptions");
         if (is_array($streamOptions)) {
             $context_options = array_replace_recursive($context_options, $streamOptions);
         }
         unset($streamOptions);
     }
     $context = stream_context_create($context_options);
     $response = file_get_contents($url, false, $context);
     // $http_response_header is set by file_get_contents with the http:// wrapper
     preg_match('/^HTTP\\/1\\.[0-1] (\\d{3})/', $http_response_header[0], $parts);
     $code = $parts[1];
     if (!$code) {
         $code = 500;
         $response = json_encode(array("error" => 'error [' . $code . ']'));
     }
     $bodyData = json_decode($response, true);
     $headers = array();
     foreach ($http_response_header as $header) {
         $parts = explode(':', $header, 2);
         if (count($parts) == 2) {
             $headers[$parts[0]] = $parts[1];
         }
     }
     return array('code' => $code, 'headers' => $headers, 'data' => $bodyData);
 }
Esempio n. 4
0
 /**
  * @inherit
  */
 public function makeRequest($method, $path, $data = array())
 {
     $url = $this->getEndpoint() . $path;
     $context_options = array($this->scheme => array('method' => 'GET', 'ignore_errors' => true, 'header' => "Content-type: application/json\r\n" . "Accept: application/json;stream=true\r\n" . "User-Agent: " . Version::userAgent() . "\r\n" . "X-Stream: true\r\n"));
     if ($this->username && $this->password) {
         $encodedAuth = base64_encode($this->username . ':' . $this->password);
         $context_options[$this->scheme]['header'] .= 'Authorization: Basic ' . $encodedAuth . "\r\n";
     }
     switch ($method) {
         case self::DELETE:
             $context_options[$this->scheme]['method'] = self::DELETE;
             break;
         case self::POST:
         case self::PUT:
             $dataString = $this->encodeData($data);
             $context_options[$this->scheme]['method'] = $method;
             $context_options[$this->scheme]['content'] = $dataString;
             $context_options[$this->scheme]['header'] .= 'Context-Length: ' . strlen($dataString) . "\r\n";
             break;
     }
     $context = stream_context_create($context_options);
     $response = file_get_contents($url, false, $context);
     if ($response === false) {
         throw new Exception("Can't open connection to " . $url);
     }
     // $http_response_header is set by file_get_contents with the http:// wrapper
     preg_match('/^HTTP\\/1\\.[0-1] (\\d{3})/', $http_response_header[0], $parts);
     $code = $parts[1];
     if (!$code) {
         $code = 500;
         $response = json_encode(array("error" => 'error [' . $code . ']'));
     }
     $bodyData = json_decode($response, true);
     $headers = array();
     foreach ($http_response_header as $header) {
         $parts = explode(':', $header, 2);
         if (count($parts) == 2) {
             $headers[$parts[0]] = $parts[1];
         }
     }
     return array('code' => $code, 'headers' => $headers, 'data' => $bodyData);
 }