diff options
Diffstat (limited to 'src/PurpleCode/PCurl/PJsonCurl.php')
-rw-r--r-- | src/PurpleCode/PCurl/PJsonCurl.php | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/PurpleCode/PCurl/PJsonCurl.php b/src/PurpleCode/PCurl/PJsonCurl.php index e5dcf26..30776a0 100644 --- a/src/PurpleCode/PCurl/PJsonCurl.php +++ b/src/PurpleCode/PCurl/PJsonCurl.php @@ -14,22 +14,36 @@ namespace PurpleCode\PCurl; class PJsonCurl extends PCurl {
private $arrayResponse;
+ private $alwaysParseResponse;
public function __construct($host) {
parent::__construct($host);
$this->arrayResponse = false;
+ $this->alwaysParseResponse = true;
$this->contentTypeJson();
}
public function call($method, $url, $payload = '') {
$payload = json_encode($payload);
- $response = parent::call($method, $url, $payload);
- return json_decode($response, $this->arrayResponse);
+ return parent::call($method, $url, $payload);
+ }
+
+ protected function postProcessResponseBody($body, $header) {
+ $body = parent::postProcessResponseBody($body, $header);
+ if ($this->alwaysParseResponse || strpos($header,'application/json')!==false) {
+ return json_decode($body, $this->arrayResponse);
+ }
+
+ return $body;
}
public function arrayResponse($arrayResponse = true) {
$this->arrayResponse = $arrayResponse;
}
+ public function alwaysParseResponse($alwaysParseResponse = true) {
+ $this->alwaysParseResponse = $alwaysParseResponse;
+ }
+
}
|