mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Added regex match support to Set::extract
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6667 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f6c30745fe
commit
5fe0038a74
2 changed files with 8 additions and 2 deletions
|
@ -404,7 +404,7 @@ class Set extends Object {
|
||||||
$contexts = array($data);
|
$contexts = array($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokens = array_slice(explode('/', $path), 1);
|
$tokens = array_slice(preg_split('/(?<!=)\/(?!])/', $path), 1);
|
||||||
do {
|
do {
|
||||||
$token = array_shift($tokens);
|
$token = array_shift($tokens);
|
||||||
$conditions = false;
|
$conditions = false;
|
||||||
|
@ -503,7 +503,9 @@ class Set extends Object {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$val = $data[$key];
|
$val = $data[$key];
|
||||||
if ($op == '=' && $val != $expected) {
|
if ($op == '=' && $expected{0} == '/') {
|
||||||
|
return preg_match($expected, $val);
|
||||||
|
} elseif ($op == '=' && $val != $expected) {
|
||||||
return false;
|
return false;
|
||||||
} elseif ($op == '!=' && $val == $expected) {
|
} elseif ($op == '!=' && $val == $expected) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -423,6 +423,10 @@ class SetTest extends UnitTestCase {
|
||||||
$expected = array(4);
|
$expected = array(4);
|
||||||
$r = Set::extract('/User/id', $single);
|
$r = Set::extract('/User/id', $single);
|
||||||
$this->assertEqual($r, $expected);
|
$this->assertEqual($r, $expected);
|
||||||
|
|
||||||
|
$expected = array(1, 3);
|
||||||
|
$r = Set::extract('/User[name=/n/]/id', $tricky);
|
||||||
|
$this->assertEqual($r, $expected);
|
||||||
|
|
||||||
$common = array(
|
$common = array(
|
||||||
array(
|
array(
|
||||||
|
|
Loading…
Add table
Reference in a new issue