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:
the_undefined 2008-04-16 19:36:19 +00:00
parent f6c30745fe
commit 5fe0038a74
2 changed files with 8 additions and 2 deletions

View file

@ -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;

View file

@ -423,6 +423,10 @@ class SetTest extends UnitTestCase {
$expected = array(4);
$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(