allows for an extra param to decode json objects into associative arrays
This commit is contained in:
Ahmad Nassri
2014-12-17 18:51:36 -05:00
parent e362fe01ec
commit 6e615557cc

View File

@@ -15,13 +15,13 @@ class HttpResponse
* @param string $raw_body the raw body of the cURL response * @param string $raw_body the raw body of the cURL response
* @param string $headers raw header string from cURL response * @param string $headers raw header string from cURL response
*/ */
public function __construct($code, $raw_body, $headers) public function __construct($code, $raw_body, $headers, $json_decode_assoc = false)
{ {
$this->code = $code; $this->code = $code;
$this->headers = $this->get_headers_from_curl_response($headers); $this->headers = $this->get_headers_from_curl_response($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 = json_decode($raw_body, $json_decode_assoc);
if (json_last_error() == JSON_ERROR_NONE) { if (json_last_error() == JSON_ERROR_NONE) {
$this->body = $json; $this->body = $json;