mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
Fix #357: Allow passing json_decode() parameters to Curl::setDefaultJsonDecoder
This commit is contained in:
+7
-2
@@ -750,11 +750,16 @@ class Curl
|
||||
* Set Default JSON Decoder
|
||||
*
|
||||
* @access public
|
||||
* @param $assoc
|
||||
* @param $depth
|
||||
* @param $options
|
||||
*/
|
||||
public function setDefaultJsonDecoder()
|
||||
{
|
||||
$this->jsonDecoder = function($response) {
|
||||
$json_obj = json_decode($response, false);
|
||||
$args = func_get_args();
|
||||
$this->jsonDecoder = function($response) use ($args) {
|
||||
array_unshift($args, $response);
|
||||
$json_obj = call_user_func_array('json_decode', $args);
|
||||
if (!($json_obj === null)) {
|
||||
$response = $json_obj;
|
||||
}
|
||||
|
||||
@@ -1040,7 +1040,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertFalse(file_exists($file_path));
|
||||
}
|
||||
|
||||
public function testJSONRequest()
|
||||
public function testJsonRequest()
|
||||
{
|
||||
foreach (
|
||||
array(
|
||||
@@ -1091,7 +1091,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testJSONResponse()
|
||||
public function testJsonResponse()
|
||||
{
|
||||
foreach (array(
|
||||
'Content-Type',
|
||||
@@ -1133,7 +1133,30 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testJSONDecoder()
|
||||
public function testJsonDecoderOptions()
|
||||
{
|
||||
// Implicit default json decoder should return object.
|
||||
$test = new Test();
|
||||
$test->server('json_response', 'GET');
|
||||
$this->assertTrue(is_object($test->curl->response));
|
||||
|
||||
// Explicit default json decoder should return object.
|
||||
$test = new Test();
|
||||
$test->curl->setDefaultJsonDecoder();
|
||||
$test->server('json_response', 'GET');
|
||||
$this->assertTrue(is_object($test->curl->response));
|
||||
|
||||
// Explicit default json decoder with options should return associative array as specified.
|
||||
$assoc = true;
|
||||
$depth = 512;
|
||||
$options = 0;
|
||||
$test = new Test();
|
||||
$test->curl->setDefaultJsonDecoder($assoc, $depth, $options);
|
||||
$test->server('json_response', 'GET');
|
||||
$this->assertTrue(is_array($test->curl->response));
|
||||
}
|
||||
|
||||
public function testJsonDecoder()
|
||||
{
|
||||
$data = array(
|
||||
'key' => 'Content-Type',
|
||||
@@ -1154,7 +1177,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(is_array($test->curl->response));
|
||||
}
|
||||
|
||||
public function testJSONContentTypeDetection()
|
||||
public function testJsonContentTypeDetection()
|
||||
{
|
||||
$json_content_types = array(
|
||||
'application/alto-costmap+json',
|
||||
|
||||
Reference in New Issue
Block a user