/** * Execute a request using curl * * @param string $url URL * @param mixed $parameters Array of parameters * @param string $http_method HTTP Method * @param array $http_headers HTTP Headers * @return array */ private function executeRequest($url, $parameters = array(), $http_method = 'GET') { $curl_options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CUSTOMREQUEST => $http_method, CURLOPT_CONNECTTIMEOUT => $this->curlConnectionTimeout, CURLOPT_TIMEOUT => $this->curlRequestTimeout); switch ($http_method) { case 'POST': $curl_options[CURLOPT_POST] = true; $curl_options[CURLOPT_POSTFIELDS] = $parameters; break; default: if (is_array($parameters)) { $url .= '?' . http_build_query($parameters, null, '&'); } elseif ($parameters) { $url .= '?' . $parameters; } break; } $curl_options[CURLOPT_URL] = $url; $ch = curl_init(); curl_setopt_array($ch, $curl_options); $result = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if ($curl_error = curl_error($ch)) { throw new VKException($curl_error, VKException::CURL_ERROR); } else { $json_decode = json_decode($result, true); } curl_close($ch); // Handling API errors if (is_array($json_decode) && isset($json_decode['error'])) { VKException::raise(array('result' => $json_decode, 'code' => $http_code)); } if ($http_code !== 200) { VKException::raise(array('http' => true, 'code' => $http_code)); } if (json_last_error() !== \JSON_ERROR_NONE) { throw new VKException('JSON decoding error', json_last_error()); } return $json_decode; }
/** * (PHP 5 >= 5.1.0)<br/> * Construct the exception. Note: The message is NOT binary safe. * * @link http://php.net/manual/en/exception.construct.php * * @param string $message [optional] The Exception message to throw. * @param int $code [optional] The Exception code. * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 */ public function __construct(ResponseInterface $response, $message = "", $code = 0, Exception $previous = null) { $this->_response = $response; parent::__construct($message, $code, $previous); // TODO: Change the autogenerated stub }