Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 62 additions & 5 deletions src/Curl/ArrayUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ class ArrayUtil
*
* @return boolean
*/
public static function is_array_assoc($array)
public static function isArrayAssoc($array)
{
return (bool)count(array_filter(array_keys($array), 'is_string'));
}

/**
* Is Array Assoc
*
* @deprecated Use ArrayUtil::isArrayAssoc().
* @access public
* @param $array
*
* @return boolean
*/
public static function is_array_assoc($array)
{
return $this->isArrayAssoc($array);
}

/**
* Is Array Multidim
*
Expand All @@ -25,7 +39,7 @@ public static function is_array_assoc($array)
*
* @return boolean
*/
public static function is_array_multidim($array)
public static function isArrayMultidim($array)
{
if (!is_array($array)) {
return false;
Expand All @@ -34,6 +48,20 @@ public static function is_array_multidim($array)
return (bool)count(array_filter($array, 'is_array'));
}

/**
* Is Array Multidim
*
* @deprecated Use ArrayUtil::isArrayMultidim().
* @access public
* @param $array
*
* @return boolean
*/
public static function is_array_multidim($array)
{
return $this->isArrayMultidim($array);
}

/**
* Array Flatten Multidim
*
Expand All @@ -43,7 +71,7 @@ public static function is_array_multidim($array)
*
* @return array
*/
public static function array_flatten_multidim($array, $prefix = false)
public static function arrayFlattenMultidim($array, $prefix = false)
{
$return = array();
if (is_array($array) || is_object($array)) {
Expand All @@ -63,7 +91,7 @@ public static function array_flatten_multidim($array, $prefix = false)
} else {
$return = array_merge(
$return,
self::array_flatten_multidim(
self::arrayFlattenMultidim(
$value,
$prefix ? $prefix . '[' . $key . ']' : $key
)
Expand All @@ -78,6 +106,21 @@ public static function array_flatten_multidim($array, $prefix = false)
return $return;
}

/**
* Array Flatten Multidim
*
* @deprecated Use ArrayUtil::arrayFlattenMultidim().
* @access public
* @param $array
* @param $prefix
*
* @return array
*/
public static function array_flatten_multidim($array, $prefix = false)
{
return $this->arrayFlattenMultidim($array, $prefix);
}

/**
* Array Random
*
Expand All @@ -86,8 +129,22 @@ public static function array_flatten_multidim($array, $prefix = false)
*
* @return mixed
*/
public static function array_random($array)
public static function arrayRandom($array)
{
return $array[mt_rand(0, count($array) - 1)];
}

/**
* Array Random
*
* @deprecated Use ArrayUtil::arrayRandom().
* @access public
* @param $array
*
* @return mixed
*/
public static function array_random($array)
{
return $this->arrayRandom($array);
}
}
4 changes: 2 additions & 2 deletions src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ interface_exists('JsonSerializable', false) &&
// Manually build a single-dimensional array from a multi-dimensional array as using curl_setopt($ch,
// CURLOPT_POSTFIELDS, $data) doesn't correctly handle multi-dimensional arrays when files are
// referenced.
if (ArrayUtil::is_array_multidim($data)) {
$data = ArrayUtil::array_flatten_multidim($data);
if (ArrayUtil::isArrayMultidim($data)) {
$data = ArrayUtil::arrayFlattenMultidim($data);
}

// Modify array values to ensure any referenced files are properly handled depending on the support of
Expand Down
2 changes: 1 addition & 1 deletion src/Curl/MultiCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ private function initHandle($curl)
// Use a random proxy for the curl instance when proxies have been set
// and the curl instance doesn't already have a proxy set.
if (is_array($this->proxies) && $curl->getOpt(CURLOPT_PROXY) === null) {
$random_proxy = ArrayUtil::array_random($this->proxies);
$random_proxy = ArrayUtil::arrayRandom($this->proxies);
$curl->setProxy($random_proxy);
}

Expand Down
16 changes: 14 additions & 2 deletions tests/PHPCurlClass/PHPCurlClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testExtensionsLoaded()

public function testArrayAssociative()
{
$this->assertTrue(\Curl\ArrayUtil::is_array_assoc(array(
$this->assertTrue(\Curl\ArrayUtil::isArrayAssoc(array(
'foo' => 'wibble',
'bar' => 'wubble',
'baz' => 'wobble',
Expand All @@ -27,7 +27,7 @@ public function testArrayAssociative()

public function testArrayIndexed()
{
$this->assertFalse(\Curl\ArrayUtil::is_array_assoc(array(
$this->assertFalse(\Curl\ArrayUtil::isArrayAssoc(array(
'wibble',
'wubble',
'wobble',
Expand Down Expand Up @@ -3457,6 +3457,18 @@ public function testUnsetHeader()
$this->assertEquals('', $curl->response);
}

public function testRemoveHeader()
{
$curl = new Curl();
$curl->get(Test::TEST_URL);
$this->assertEquals('127.0.0.1:8000', $curl->requestHeaders['host']);

$curl = new Curl();
$curl->removeHeader('HOST');
$curl->get(Test::TEST_URL);
$this->assertEquals('', $curl->requestHeaders['host']);
}

public function testGetInfo()
{
$test = new Test();
Expand Down