Skip to content

Commit e782f41

Browse files
authored
Merge pull request php-curl-class#589 from zachborboa/master
Use camelCase for ArrayUtil function names and deprecate old snake_case names
2 parents c7d66bf + 505663a commit e782f41

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

src/Curl/ArrayUtil.php

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,25 @@ class ArrayUtil
1212
*
1313
* @return boolean
1414
*/
15-
public static function is_array_assoc($array)
15+
public static function isArrayAssoc($array)
1616
{
1717
return (bool)count(array_filter(array_keys($array), 'is_string'));
1818
}
1919

20+
/**
21+
* Is Array Assoc
22+
*
23+
* @deprecated Use ArrayUtil::isArrayAssoc().
24+
* @access public
25+
* @param $array
26+
*
27+
* @return boolean
28+
*/
29+
public static function is_array_assoc($array)
30+
{
31+
return $this->isArrayAssoc($array);
32+
}
33+
2034
/**
2135
* Is Array Multidim
2236
*
@@ -25,7 +39,7 @@ public static function is_array_assoc($array)
2539
*
2640
* @return boolean
2741
*/
28-
public static function is_array_multidim($array)
42+
public static function isArrayMultidim($array)
2943
{
3044
if (!is_array($array)) {
3145
return false;
@@ -34,6 +48,20 @@ public static function is_array_multidim($array)
3448
return (bool)count(array_filter($array, 'is_array'));
3549
}
3650

51+
/**
52+
* Is Array Multidim
53+
*
54+
* @deprecated Use ArrayUtil::isArrayMultidim().
55+
* @access public
56+
* @param $array
57+
*
58+
* @return boolean
59+
*/
60+
public static function is_array_multidim($array)
61+
{
62+
return $this->isArrayMultidim($array);
63+
}
64+
3765
/**
3866
* Array Flatten Multidim
3967
*
@@ -43,7 +71,7 @@ public static function is_array_multidim($array)
4371
*
4472
* @return array
4573
*/
46-
public static function array_flatten_multidim($array, $prefix = false)
74+
public static function arrayFlattenMultidim($array, $prefix = false)
4775
{
4876
$return = array();
4977
if (is_array($array) || is_object($array)) {
@@ -63,7 +91,7 @@ public static function array_flatten_multidim($array, $prefix = false)
6391
} else {
6492
$return = array_merge(
6593
$return,
66-
self::array_flatten_multidim(
94+
self::arrayFlattenMultidim(
6795
$value,
6896
$prefix ? $prefix . '[' . $key . ']' : $key
6997
)
@@ -78,6 +106,21 @@ public static function array_flatten_multidim($array, $prefix = false)
78106
return $return;
79107
}
80108

109+
/**
110+
* Array Flatten Multidim
111+
*
112+
* @deprecated Use ArrayUtil::arrayFlattenMultidim().
113+
* @access public
114+
* @param $array
115+
* @param $prefix
116+
*
117+
* @return array
118+
*/
119+
public static function array_flatten_multidim($array, $prefix = false)
120+
{
121+
return $this->arrayFlattenMultidim($array, $prefix);
122+
}
123+
81124
/**
82125
* Array Random
83126
*
@@ -86,8 +129,22 @@ public static function array_flatten_multidim($array, $prefix = false)
86129
*
87130
* @return mixed
88131
*/
89-
public static function array_random($array)
132+
public static function arrayRandom($array)
90133
{
91134
return $array[mt_rand(0, count($array) - 1)];
92135
}
136+
137+
/**
138+
* Array Random
139+
*
140+
* @deprecated Use ArrayUtil::arrayRandom().
141+
* @access public
142+
* @param $array
143+
*
144+
* @return mixed
145+
*/
146+
public static function array_random($array)
147+
{
148+
return $this->arrayRandom($array);
149+
}
93150
}

src/Curl/Curl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ interface_exists('JsonSerializable', false) &&
157157
// Manually build a single-dimensional array from a multi-dimensional array as using curl_setopt($ch,
158158
// CURLOPT_POSTFIELDS, $data) doesn't correctly handle multi-dimensional arrays when files are
159159
// referenced.
160-
if (ArrayUtil::is_array_multidim($data)) {
161-
$data = ArrayUtil::array_flatten_multidim($data);
160+
if (ArrayUtil::isArrayMultidim($data)) {
161+
$data = ArrayUtil::arrayFlattenMultidim($data);
162162
}
163163

164164
// Modify array values to ensure any referenced files are properly handled depending on the support of

src/Curl/MultiCurl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ private function initHandle($curl)
952952
// Use a random proxy for the curl instance when proxies have been set
953953
// and the curl instance doesn't already have a proxy set.
954954
if (is_array($this->proxies) && $curl->getOpt(CURLOPT_PROXY) === null) {
955-
$random_proxy = ArrayUtil::array_random($this->proxies);
955+
$random_proxy = ArrayUtil::arrayRandom($this->proxies);
956956
$curl->setProxy($random_proxy);
957957
}
958958

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testExtensionsLoaded()
1818

1919
public function testArrayAssociative()
2020
{
21-
$this->assertTrue(\Curl\ArrayUtil::is_array_assoc(array(
21+
$this->assertTrue(\Curl\ArrayUtil::isArrayAssoc(array(
2222
'foo' => 'wibble',
2323
'bar' => 'wubble',
2424
'baz' => 'wobble',
@@ -27,7 +27,7 @@ public function testArrayAssociative()
2727

2828
public function testArrayIndexed()
2929
{
30-
$this->assertFalse(\Curl\ArrayUtil::is_array_assoc(array(
30+
$this->assertFalse(\Curl\ArrayUtil::isArrayAssoc(array(
3131
'wibble',
3232
'wubble',
3333
'wobble',
@@ -3457,6 +3457,18 @@ public function testUnsetHeader()
34573457
$this->assertEquals('', $curl->response);
34583458
}
34593459

3460+
public function testRemoveHeader()
3461+
{
3462+
$curl = new Curl();
3463+
$curl->get(Test::TEST_URL);
3464+
$this->assertEquals('127.0.0.1:8000', $curl->requestHeaders['host']);
3465+
3466+
$curl = new Curl();
3467+
$curl->removeHeader('HOST');
3468+
$curl->get(Test::TEST_URL);
3469+
$this->assertEquals('', $curl->requestHeaders['host']);
3470+
}
3471+
34603472
public function testGetInfo()
34613473
{
34623474
$test = new Test();

0 commit comments

Comments
 (0)