mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Revert "Fixing Set::filter() not predictably filtering in a recursive
fashion. While a minor change in behavior, more predictable and uniform
behavior is worth it." Refs #1431
This reverts commit 6e2ffafe54
.
This commit is contained in:
parent
8754d11aed
commit
4f94b715ec
2 changed files with 3 additions and 27 deletions
|
@ -68,22 +68,10 @@ class Set {
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function filter($var, $isArray = false) {
|
function filter($var, $isArray = false) {
|
||||||
foreach ((array)$var as $k => $v) {
|
if (is_array($var) && (!empty($var) || $isArray)) {
|
||||||
if (!empty($v) && is_array($v)) {
|
return array_filter($var, array('Set', 'filter'));
|
||||||
$var[$k] = array_filter($v, array('Set', '_filter'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return array_filter($var, array('Set', '_filter'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set::filter callback function
|
|
||||||
*
|
|
||||||
* @param array $var Array to filter.
|
|
||||||
* @return boolean
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
function _filter($var) {
|
|
||||||
if ($var === 0 || $var === '0' || !empty($var)) {
|
if ($var === 0 || $var === '0' || !empty($var)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,20 +88,8 @@ class SetTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testFilter() {
|
function testFilter() {
|
||||||
$result = Set::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false)));
|
$result = Set::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false)));
|
||||||
$expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be'));
|
$expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be', false));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
|
|
||||||
$result = Set::filter(array(1, array(false)));
|
|
||||||
$expected = array(1);
|
|
||||||
$this->assertEqual($expected, $result);
|
|
||||||
|
|
||||||
$result = Set::filter(array(1, array(false, false)));
|
|
||||||
$expected = array(1);
|
|
||||||
$this->assertEqual($expected, $result);
|
|
||||||
|
|
||||||
$result = Set::filter(array(1, array('empty', false)));
|
|
||||||
$expected = array(1, array('empty'));
|
|
||||||
$this->assertEqual($expected, $result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue