This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into hotfix/json-renderer-merge-unnamed-children
- Loading branch information
57 parents
213395c
+
8e514a8
+
2f30186
+
bb4ed65
+
132d5b6
+
030ff33
+
f2f20f3
+
a50e133
+
4c554ee
+
dbfb1b8
+
ccab83f
+
00b350f
+
78945d0
+
f0e5f4b
+
ceb7d8c
+
9e124d1
+
3de5912
+
b6a974a
+
10a6438
+
cb6c1e7
+
18afd6c
+
3baf1bd
+
c800904
+
f52dcb8
+
126ccb2
+
e7d6206
+
e2d24ab
+
ec1abfc
+
290ea90
+
9f4ca1b
+
edaa760
+
c4c0c95
+
d21f055
+
5b18029
+
e6b97af
+
010fb36
+
64c7b8d
+
636523e
+
4cc2cd6
+
e34098a
+
16367cd
+
943c77f
+
8226e5b
+
0b47726
+
3cd8a03
+
cc4782c
+
9c653a6
+
656dbe5
+
9bce1ba
+
7dc18ca
+
861130d
+
2d2ffbd
+
4f413a5
+
2e1067a
+
1d082e4
+
e8aeb79
+
9ae4cbc
commit b562091
Showing
6 changed files
with
638 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,260 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stdlib; | ||
|
||
use Traversable; | ||
|
||
/** | ||
* Utility class for testing and manipulation of PHP arrays. | ||
* | ||
* Declared abstract, as we have no need for instantiation. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
abstract class ArrayUtils | ||
{ | ||
/** | ||
* Test whether an array contains one or more string keys | ||
* | ||
* @param mixed $value | ||
* @param bool $allowEmpty Should an empty array() return true | ||
* @return bool | ||
*/ | ||
public static function hasStringKeys($value, $allowEmpty = false) | ||
{ | ||
if (!is_array($value)) { | ||
return false; | ||
} | ||
|
||
if (!$value) { | ||
return $allowEmpty; | ||
} | ||
|
||
return count(array_filter(array_keys($value), 'is_string')) > 0; | ||
} | ||
|
||
/** | ||
* Test whether an array contains one or more integer keys | ||
* | ||
* @param mixed $value | ||
* @param bool $allowEmpty Should an empty array() return true | ||
* @return bool | ||
*/ | ||
public static function hasIntegerKeys($value, $allowEmpty = false) | ||
{ | ||
if (!is_array($value)) { | ||
return false; | ||
} | ||
|
||
if (!$value) { | ||
return $allowEmpty; | ||
} | ||
|
||
return count(array_filter(array_keys($value), 'is_int')) > 0; | ||
} | ||
|
||
/** | ||
* Test whether an array contains one or more numeric keys. | ||
* | ||
* A numeric key can be one of the following: | ||
* - an integer 1, | ||
* - a string with a number '20' | ||
* - a string with negative number: '-1000' | ||
* - a float: 2.2120, -78.150999 | ||
* - a string with float: '4000.99999', '-10.10' | ||
* | ||
* @param mixed $value | ||
* @param bool $allowEmpty Should an empty array() return true | ||
* @return bool | ||
*/ | ||
public static function hasNumericKeys($value, $allowEmpty = false) | ||
{ | ||
if (!is_array($value)) { | ||
return false; | ||
} | ||
|
||
if (!$value) { | ||
return $allowEmpty; | ||
} | ||
|
||
return count(array_filter(array_keys($value), 'is_numeric')) > 0; | ||
} | ||
|
||
/** | ||
* Test whether an array is a list | ||
* | ||
* A list is a collection of values assigned to continuous integer keys | ||
* starting at 0 and ending at count() - 1. | ||
* | ||
* For example: | ||
* <code> | ||
* $list = array( 'a','b','c','d' ); | ||
* $list = array( | ||
* 0 => 'foo', | ||
* 1 => 'bar', | ||
* 2 => array( 'foo' => 'baz' ), | ||
* ); | ||
* </code> | ||
* | ||
* @param mixed $value | ||
* @param bool $allowEmpty Is an empty list a valid list? | ||
* @return bool | ||
*/ | ||
public static function isList($value, $allowEmpty = false) | ||
{ | ||
if (!is_array($value)) { | ||
return false; | ||
} | ||
|
||
if (!$value) { | ||
return $allowEmpty; | ||
} | ||
|
||
return (array_values($value) === $value); | ||
} | ||
|
||
/** | ||
* Test whether an array is a hash table. | ||
* | ||
* An array is a hash table if: | ||
* | ||
* 1. Contains one or more non-integer keys, or | ||
* 2. Integer keys are non-continuous or misaligned (not starting with 0) | ||
* | ||
* For example: | ||
* <code> | ||
* $hash = array( | ||
* 'foo' => 15, | ||
* 'bar' => false, | ||
* ); | ||
* $hash = array( | ||
* 1995 => 'Birth of PHP', | ||
* 2009 => 'PHP 5.3.0', | ||
* 2012 => 'PHP 5.4.0', | ||
* ); | ||
* $hash = array( | ||
* 'formElement, | ||
* 'options' => array( 'debug' => true ), | ||
* ); | ||
* </code> | ||
* | ||
* @param mixed $value | ||
* @param bool $allowEmpty Is an empty array() a valid hash table? | ||
* @return bool | ||
*/ | ||
public static function isHashTable($value, $allowEmpty = false) | ||
{ | ||
if (!is_array($value)) { | ||
return false; | ||
} | ||
|
||
if (!$value) { | ||
return $allowEmpty; | ||
} | ||
|
||
return (array_values($value) !== $value); | ||
} | ||
|
||
/** | ||
* Convert an iterator to an array. | ||
* | ||
* Converts an iterator to an array. The $recursive flag, on by default, | ||
* hints whether or not you want to do so recursively. | ||
* | ||
* @param array|Traversable $iterator The array or Traversable object to convert | ||
* @param bool $recursive Recursively check all nested structures | ||
* @return array | ||
*/ | ||
public static function iteratorToArray($iterator, $recursive = true) | ||
{ | ||
if (!is_array($iterator) && !$iterator instanceof Traversable) { | ||
throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable object'); | ||
} | ||
|
||
if (!$recursive) { | ||
if (is_array($iterator)) { | ||
return $iterator; | ||
} | ||
|
||
return iterator_to_array($iterator); | ||
} | ||
|
||
if (method_exists($iterator, 'toArray')) { | ||
return $iterator->toArray(); | ||
} | ||
|
||
$array = array(); | ||
foreach ($iterator as $key => $value) { | ||
if (is_scalar($value)) { | ||
$array[$key] = $value; | ||
continue; | ||
} | ||
|
||
if ($value instanceof Traversable) { | ||
$array[$key] = static::iteratorToArray($value, $recursive); | ||
continue; | ||
} | ||
|
||
if (is_array($value)) { | ||
$array[$key] = static::iteratorToArray($value, $recursive); | ||
continue; | ||
} | ||
|
||
$array[$key] = $value; | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
/** | ||
* Merge two arrays together. | ||
* | ||
* If an integer key exists in both arrays, the value from the second array | ||
* will be appended the the first array. If both values are arrays, they | ||
* are merged together, else the value of the second array overwrites the | ||
* one of the first array. | ||
* | ||
* @param array $a | ||
* @param array $b | ||
* @return array | ||
*/ | ||
public static function merge(array $a, array $b) | ||
{ | ||
foreach ($b as $key => $value) { | ||
if (array_key_exists($key, $a)) { | ||
if (is_int($key)) { | ||
$a[] = $value; | ||
} elseif (is_array($value) && is_array($a[$key])) { | ||
$a[$key] = self::merge($a[$key], $value); | ||
} else { | ||
$a[$key] = $value; | ||
} | ||
} else { | ||
$a[$key] = $value; | ||
} | ||
} | ||
|
||
return $a; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.