feat(json): json pecl extension may be available all the time

This commit is contained in:
Ahmad Nassri
2016-02-24 22:07:25 -05:00
parent f7f13bd940
commit 0f3a22d63e
3 changed files with 12 additions and 7 deletions

5
.gitignore vendored
View File

@@ -1,6 +1,7 @@
.idea
.DS_Store .DS_Store
.idea
build build
vendor
composer.lock composer.lock
composer.phar composer.phar
coverage
vendor

View File

@@ -8,8 +8,10 @@
"author": "Mashape <opensource@mashape.com> (https://www.mashape.com)", "author": "Mashape <opensource@mashape.com> (https://www.mashape.com)",
"require": { "require": {
"php": ">=5.4.0", "php": ">=5.4.0",
"ext-curl": "*", "ext-curl": "*"
"ext-json": "*" },
"suggest": {
"ext-json": "Allows using JSON Bodies for sending and parsing requests"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.4", "phpunit/phpunit": "~4.4",

View File

@@ -25,10 +25,12 @@ class Response
// make sure raw_body is the first argument // make sure raw_body is the first argument
array_unshift($json_args, $raw_body); array_unshift($json_args, $raw_body);
$json = call_user_func_array('json_decode', $json_args); if (function_exists('json_decode')) {
$json = call_user_func_array('json_decode', $json_args);
if (json_last_error() === JSON_ERROR_NONE) { if (json_last_error() === JSON_ERROR_NONE) {
$this->body = $json; $this->body = $json;
}
} }
} }