mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-27 10:33:37 +00:00
Merge branch 'master' of https://github.com/php-curl-class/php-curl-class into php-curl-class-master
Conflicts: Curl.class.php
This commit is contained in:
+9
-2
@@ -84,9 +84,12 @@ class Curl {
|
||||
function http_build_multi_query($data, $key=NULL) {
|
||||
$query = array();
|
||||
|
||||
$is_array_assoc = is_array_assoc($data);
|
||||
|
||||
foreach ($data as $k => $value) {
|
||||
if (is_string($value) || is_int($value)) {
|
||||
$query[] = urlencode(is_null($key) ? $k : $key.'['.$k.']') . '=' . rawurlencode($value);
|
||||
if (is_string($value)) {
|
||||
$brackets = $is_array_assoc ? '[' . $k . ']' : '[]';
|
||||
$query[] = urlencode(is_null($key) ? $k : $key . $brackets) . '=' . rawurlencode($value);
|
||||
}
|
||||
else if (is_array($value)) {
|
||||
$query[] = $this->http_build_multi_query($value, $k);
|
||||
@@ -168,6 +171,10 @@ class Curl {
|
||||
public $response = NULL;
|
||||
}
|
||||
|
||||
function is_array_assoc($array) {
|
||||
return (bool)count(array_filter(array_keys($array), 'is_string'));
|
||||
}
|
||||
|
||||
function is_array_multidim($array) {
|
||||
if (!is_array($array)) {
|
||||
return FALSE;
|
||||
|
||||
@@ -10,6 +10,22 @@ class CurlTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertTrue(extension_loaded('curl'));
|
||||
}
|
||||
|
||||
public function testArrayAssociative() {
|
||||
$this->assertTrue(is_array_assoc(array(
|
||||
'foo' => 'wibble',
|
||||
'bar' => 'wubble',
|
||||
'baz' => 'wobble',
|
||||
)));
|
||||
}
|
||||
|
||||
public function testArrayIndexed() {
|
||||
$this->assertFalse(is_array_assoc(array(
|
||||
'wibble',
|
||||
'wubble',
|
||||
'wobble',
|
||||
)));
|
||||
}
|
||||
|
||||
public function testUserAgent() {
|
||||
$test = new Test();
|
||||
$test->curl->setUserAgent(Curl::USER_AGENT);
|
||||
@@ -43,6 +59,20 @@ class CurlTest extends PHPUnit_Framework_TestCase {
|
||||
)) === 'post');
|
||||
}
|
||||
|
||||
public function testPostAssociativeArrayData() {
|
||||
$test = new Test();
|
||||
$this->assertTrue($test->server('POST', array(
|
||||
'test' => 'post_multidimensional',
|
||||
'username' => 'myusername',
|
||||
'password' => 'mypassword',
|
||||
'more_data' => array(
|
||||
'param1' => 'something',
|
||||
'param2' => 'other thing',
|
||||
'param3' => '123',
|
||||
),
|
||||
)) === 'test=post_multidimensional&username=myusername&password=mypassword&more_data%5Bparam1%5D=something&more_data%5Bparam2%5D=other%20thing&more_data%5Bparam3%5D=123');
|
||||
}
|
||||
|
||||
public function testPostMultidimensionalData() {
|
||||
$test = new Test();
|
||||
$this->assertTrue($test->server('POST', array(
|
||||
|
||||
Reference in New Issue
Block a user