diff options
author | theres <dmarkiew@CNU3429M9W.nsn-intra.net> | 2014-07-15 09:44:07 +0200 |
---|---|---|
committer | theres <dmarkiew@CNU3429M9W.nsn-intra.net> | 2014-07-15 09:44:07 +0200 |
commit | 090e64bd20a40ed55c79025e611ba2c6a45c80df (patch) | |
tree | b9a284b086b69e057386e11333d7ff15a130834d /src/PurpleCode/PCurl/PJsonCurl.php | |
parent | 1884e50d534f9ca82527d06861cb7064fe1d9b40 (diff) | |
download | php.curl-090e64bd20a40ed55c79025e611ba2c6a45c80df.zip php.curl-090e64bd20a40ed55c79025e611ba2c6a45c80df.tar.gz php.curl-090e64bd20a40ed55c79025e611ba2c6a45c80df.tar.bz2 |
PCurl will now return PCurlResponse object instead of raw body. PJsonCurl
also, but will try to parse JSON and throw an exception when fail to
parse.
Diffstat (limited to 'src/PurpleCode/PCurl/PJsonCurl.php')
-rw-r--r-- | src/PurpleCode/PCurl/PJsonCurl.php | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/src/PurpleCode/PCurl/PJsonCurl.php b/src/PurpleCode/PCurl/PJsonCurl.php index 30776a0..aad8bd4 100644 --- a/src/PurpleCode/PCurl/PJsonCurl.php +++ b/src/PurpleCode/PCurl/PJsonCurl.php @@ -11,39 +11,27 @@ namespace PurpleCode\PCurl;
+use PurpleCode\PCurl\PCurlJsonResponse;
+
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);
- 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;
+ $response = parent::call($method, $url, $payload);
+ return new PCurlJsonResponse($response->getHeader(), $response->getBody(), $this->arrayResponse);
}
public function arrayResponse($arrayResponse = true) {
$this->arrayResponse = $arrayResponse;
}
- public function alwaysParseResponse($alwaysParseResponse = true) {
- $this->alwaysParseResponse = $alwaysParseResponse;
- }
-
}
|