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);
|
||||
}
|
||||
|
||||
$tokens = array_slice(explode('/', $path), 1);
|
||||
$tokens = array_slice(preg_split('/(?<!=)\/(?!])/', $path), 1);
|
||||
do {
|
||||
$token = array_shift($tokens);
|
||||
$conditions = false;
|
||||
|
@ -503,7 +503,9 @@ class Set extends Object {
|
|||
return false;
|
||||
}
|
||||
$val = $data[$key];
|
||||
if ($op == '=' && $val != $expected) {
|
||||
if ($op == '=' && $expected{0} == '/') {
|
||||
return preg_match($expected, $val);
|
||||
} elseif ($op == '=' && $val != $expected) {
|
||||
return false;
|
||||
} elseif ($op == '!=' && $val == $expected) {
|
||||
return false;
|
||||
|
|
|
@ -424,6 +424,10 @@ class SetTest extends UnitTestCase {
|
|||
$r = Set::extract('/User/id', $single);
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
$expected = array(1, 3);
|
||||
$r = Set::extract('/User[name=/n/]/id', $tricky);
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
$common = array(
|
||||
array(
|
||||
'Article' => array(
|
||||
|
|
Loading…
Add table
Reference in a new issue