Added support for conditions on multi-nested numerically indexed items

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6657 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-04-13 13:27:12 +00:00
parent 593c4d7245
commit 1fdd44f6b2
2 changed files with 8 additions and 1 deletions

View file

@ -417,13 +417,16 @@ class Set extends Object {
} }
$match = false; $match = false;
if (array_key_exists($token, $context['item']) && (!$conditions || Set::matches($conditions, $context['item'][$token], $i))) { if (array_key_exists($token, $context['item'])) {
$items = $context['item'][$token]; $items = $context['item'][$token];
if (!is_array($items) || !isset($items[0])) { if (!is_array($items) || !isset($items[0])) {
$items = array($items); $items = array($items);
} }
foreach ($items as $item) { foreach ($items as $item) {
if ($conditions && !Set::matches($conditions, $item, $i)) {
continue;
}
$matches[] = array( $matches[] = array(
'trace' => am($context['trace'], $context['key']), 'trace' => am($context['trace'], $context['key']),
'key' => $token, 'key' => $token,

View file

@ -476,6 +476,10 @@ class SetTest extends UnitTestCase {
$r = Set::extract('/Comment/id', $common); $r = Set::extract('/Comment/id', $common);
$expected = array(1, 2, 3, 4, 5); $expected = array(1, 2, 3, 4, 5);
$this->assertEqual($r, $expected); $this->assertEqual($r, $expected);
$expected = array(1, 2, 4, 5);
$r = Set::extract('/Comment[id!=3]/id', $common);
$this->assertEqual($r, $expected);
} }
/** /**
* undocumented function * undocumented function