PSR: PHP keywords in proper lower case + more camelCasing
This commit is contained in:
@@ -18,7 +18,7 @@ class HttpResponse
|
|||||||
public function __construct($code, $raw_body, $headers, $json_decode_assoc = false)
|
public function __construct($code, $raw_body, $headers, $json_decode_assoc = false)
|
||||||
{
|
{
|
||||||
$this->code = $code;
|
$this->code = $code;
|
||||||
$this->headers = $this->GetHeadersFromCurlResponse($headers);
|
$this->headers = $this->getHeadersFromCurlResponse($headers);
|
||||||
$this->raw_body = $raw_body;
|
$this->raw_body = $raw_body;
|
||||||
$this->body = $raw_body;
|
$this->body = $raw_body;
|
||||||
$json = json_decode($raw_body, $json_decode_assoc);
|
$json = json_decode($raw_body, $json_decode_assoc);
|
||||||
@@ -60,7 +60,7 @@ class HttpResponse
|
|||||||
* @param string $headers header string from cURL response
|
* @param string $headers header string from cURL response
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function GetHeadersFromCurlResponse($headers)
|
private function getHeadersFromCurlResponse($headers)
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
$headers = explode("\r\n", $headers);
|
$headers = explode("\r\n", $headers);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Unirest
|
|||||||
* @param string $password Basic Authentication password
|
* @param string $password Basic Authentication password
|
||||||
* @return string|stdObj response string or stdObj if response is json-decodable
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
||||||
*/
|
*/
|
||||||
public static function get($url, $headers = array(), $parameters = NULL, $username = NULL, $password = NULL)
|
public static function get($url, $headers = array(), $parameters = null, $username = null, $password = null)
|
||||||
{
|
{
|
||||||
return self::request(HttpMethod::GET, $url, $parameters, $headers, $username, $password);
|
return self::request(HttpMethod::GET, $url, $parameters, $headers, $username, $password);
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ class Unirest
|
|||||||
* @param string $password Basic Authentication password
|
* @param string $password Basic Authentication password
|
||||||
* @return string|stdObj response string or stdObj if response is json-decodable
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
||||||
*/
|
*/
|
||||||
public static function post($url, $headers = array(), $body = NULL, $username = NULL, $password = NULL)
|
public static function post($url, $headers = array(), $body = null, $username = null, $password = null)
|
||||||
{
|
{
|
||||||
return self::request(HttpMethod::POST, $url, $body, $headers, $username, $password);
|
return self::request(HttpMethod::POST, $url, $body, $headers, $username, $password);
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ class Unirest
|
|||||||
* @param string $password Basic Authentication password
|
* @param string $password Basic Authentication password
|
||||||
* @return string|stdObj response string or stdObj if response is json-decodable
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
||||||
*/
|
*/
|
||||||
public static function delete($url, $headers = array(), $body = NULL, $username = NULL, $password = NULL)
|
public static function delete($url, $headers = array(), $body = null, $username = null, $password = null)
|
||||||
{
|
{
|
||||||
return self::request(HttpMethod::DELETE, $url, $body, $headers, $username, $password);
|
return self::request(HttpMethod::DELETE, $url, $body, $headers, $username, $password);
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ class Unirest
|
|||||||
* @param string $password Basic Authentication password
|
* @param string $password Basic Authentication password
|
||||||
* @return string|stdObj response string or stdObj if response is json-decodable
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
||||||
*/
|
*/
|
||||||
public static function put($url, $headers = array(), $body = NULL, $username = NULL, $password = NULL)
|
public static function put($url, $headers = array(), $body = null, $username = null, $password = null)
|
||||||
{
|
{
|
||||||
return self::request(HttpMethod::PUT, $url, $body, $headers, $username, $password);
|
return self::request(HttpMethod::PUT, $url, $body, $headers, $username, $password);
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ class Unirest
|
|||||||
* @param string $password Basic Authentication password
|
* @param string $password Basic Authentication password
|
||||||
* @return string|stdObj response string or stdObj if response is json-decodable
|
* @return string|stdObj response string or stdObj if response is json-decodable
|
||||||
*/
|
*/
|
||||||
public static function patch($url, $headers = array(), $body = NULL, $username = NULL, $password = NULL)
|
public static function patch($url, $headers = array(), $body = null, $username = null, $password = null)
|
||||||
{
|
{
|
||||||
return self::request(HttpMethod::PATCH, $url, $body, $headers, $username, $password);
|
return self::request(HttpMethod::PATCH, $url, $body, $headers, $username, $password);
|
||||||
}
|
}
|
||||||
@@ -132,16 +132,16 @@ class Unirest
|
|||||||
* This function is useful for serializing multidimensional arrays, and avoid getting
|
* This function is useful for serializing multidimensional arrays, and avoid getting
|
||||||
* the "Array to string conversion" notice
|
* the "Array to string conversion" notice
|
||||||
*/
|
*/
|
||||||
public static function http_build_query_for_curl($arrays, &$new = array(), $prefix = null)
|
public static function buildHTTPCurlQuery($arrays, &$new = array(), $prefix = null)
|
||||||
{
|
{
|
||||||
if (is_object($arrays)) {
|
if (is_object($arrays)) {
|
||||||
$arrays = get_object_vars($arrays);
|
$arrays = get_object_vars($arrays);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($arrays AS $key => $value) {
|
foreach ($arrays as $key => $value) {
|
||||||
$k = isset($prefix) ? $prefix . '[' . $key . ']' : $key;
|
$k = isset($prefix) ? $prefix . '[' . $key . ']' : $key;
|
||||||
if (!$value instanceof \CURLFile AND (is_array($value) OR is_object($value))) {
|
if (!$value instanceof \CURLFile and (is_array($value) or is_object($value))) {
|
||||||
self::http_build_query_for_curl($value, $new, $k);
|
self::buildHTTPCurlQuery($value, $new, $k);
|
||||||
} else {
|
} else {
|
||||||
$new[$k] = $value;
|
$new[$k] = $value;
|
||||||
}
|
}
|
||||||
@@ -159,10 +159,11 @@ class Unirest
|
|||||||
* @throws Exception if a cURL error occurs
|
* @throws Exception if a cURL error occurs
|
||||||
* @return HttpResponse
|
* @return HttpResponse
|
||||||
*/
|
*/
|
||||||
private static function request($httpMethod, $url, $body = NULL, $headers = array(), $username = NULL, $password = NULL, $json_decode_assoc = false)
|
private static function request($httpMethod, $url, $body = null, $headers = array(), $username = null, $password = null, $json_decode_assoc = false)
|
||||||
{
|
{
|
||||||
if ($headers == NULL)
|
if ($headers == null) {
|
||||||
$headers = array();
|
$headers = array();
|
||||||
|
}
|
||||||
|
|
||||||
$lowercaseHeaders = array();
|
$lowercaseHeaders = array();
|
||||||
$finalHeaders = array_merge($headers, Unirest::$defaultHeaders);
|
$finalHeaders = array_merge($headers, Unirest::$defaultHeaders);
|
||||||
@@ -186,7 +187,7 @@ class Unirest
|
|||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
|
||||||
|
|
||||||
if (is_array($body) || $body instanceof Traversable) {
|
if (is_array($body) || $body instanceof Traversable) {
|
||||||
self::http_build_query_for_curl($body, $postBody);
|
self::buildHTTPCurlQuery($body, $postBody);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
|
||||||
} else {
|
} else {
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||||
@@ -198,7 +199,7 @@ class Unirest
|
|||||||
$url .= "?";
|
$url .= "?";
|
||||||
}
|
}
|
||||||
|
|
||||||
self::http_build_query_for_curl($body, $postBody);
|
self::buildHTTPCurlQuery($body, $postBody);
|
||||||
$url .= urldecode(http_build_query($postBody));
|
$url .= urldecode(http_build_query($postBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,6 +222,7 @@ class Unirest
|
|||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$error = curl_error($ch);
|
$error = curl_error($ch);
|
||||||
|
|
||||||
if ($error) {
|
if ($error) {
|
||||||
throw new Exception($error);
|
throw new Exception($error);
|
||||||
}
|
}
|
||||||
@@ -267,8 +269,9 @@ class Unirest
|
|||||||
$query = '?' . http_build_query(self::getArrayFromQuerystring($url_parsed['query']));
|
$query = '?' . http_build_query(self::getArrayFromQuerystring($url_parsed['query']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($port && $port[0] != ":")
|
if ($port && $port[0] != ":") {
|
||||||
$port = ":" . $port;
|
$port = ":" . $port;
|
||||||
|
}
|
||||||
|
|
||||||
$result = $scheme . $host . $port . $path . $query;
|
$result = $scheme . $host . $port . $path . $query;
|
||||||
return $result;
|
return $result;
|
||||||
@@ -279,7 +282,6 @@ class Unirest
|
|||||||
$key = trim(strtolower($key));
|
$key = trim(strtolower($key));
|
||||||
return $key . ": " . $val;
|
return $key . ": " . $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('http_chunked_decode')) {
|
if (!function_exists('http_chunked_decode')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user