From 1fdd44f6b21830473fd0ea8dc8a70695fbb623e5 Mon Sep 17 00:00:00 2001 From: the_undefined Date: Sun, 13 Apr 2008 13:27:12 +0000 Subject: [PATCH] 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 --- cake/libs/set.php | 5 ++++- cake/tests/cases/libs/set.test.php | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index a2ad13465..8cf170b62 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -417,13 +417,16 @@ class Set extends Object { } $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]; if (!is_array($items) || !isset($items[0])) { $items = array($items); } foreach ($items as $item) { + if ($conditions && !Set::matches($conditions, $item, $i)) { + continue; + } $matches[] = array( 'trace' => am($context['trace'], $context['key']), 'key' => $token, diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index d30866ab9..a5404e98b 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -476,6 +476,10 @@ class SetTest extends UnitTestCase { $r = Set::extract('/Comment/id', $common); $expected = array(1, 2, 3, 4, 5); $this->assertEqual($r, $expected); + + $expected = array(1, 2, 4, 5); + $r = Set::extract('/Comment[id!=3]/id', $common); + $this->assertEqual($r, $expected); } /** * undocumented function