mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
Use camelCase for ArrayUtil function names and deprecate old snake_case names
This commit is contained in:
+62
-5
@@ -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
|
||||
*
|
||||
@@ -25,7 +39,7 @@ class ArrayUtil
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function is_array_multidim($array)
|
||||
public static function isArrayMultidim($array)
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
@@ -34,6 +48,20 @@ class ArrayUtil
|
||||
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
|
||||
*
|
||||
@@ -43,7 +71,7 @@ class ArrayUtil
|
||||
*
|
||||
* @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)) {
|
||||
@@ -63,7 +91,7 @@ class ArrayUtil
|
||||
} else {
|
||||
$return = array_merge(
|
||||
$return,
|
||||
self::array_flatten_multidim(
|
||||
self::arrayFlattenMultidim(
|
||||
$value,
|
||||
$prefix ? $prefix . '[' . $key . ']' : $key
|
||||
)
|
||||
@@ -78,6 +106,21 @@ class ArrayUtil
|
||||
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
|
||||
*
|
||||
@@ -86,8 +129,22 @@ class ArrayUtil
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -157,8 +157,8 @@ class Curl
|
||||
// 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
|
||||
|
||||
@@ -952,7 +952,7 @@ class MultiCurl
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
public function testArrayAssociative()
|
||||
{
|
||||
$this->assertTrue(\Curl\ArrayUtil::is_array_assoc(array(
|
||||
$this->assertTrue(\Curl\ArrayUtil::isArrayAssoc(array(
|
||||
'foo' => 'wibble',
|
||||
'bar' => 'wubble',
|
||||
'baz' => 'wobble',
|
||||
@@ -27,7 +27,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
public function testArrayIndexed()
|
||||
{
|
||||
$this->assertFalse(\Curl\ArrayUtil::is_array_assoc(array(
|
||||
$this->assertFalse(\Curl\ArrayUtil::isArrayAssoc(array(
|
||||
'wibble',
|
||||
'wubble',
|
||||
'wobble',
|
||||
|
||||
Reference in New Issue
Block a user