From c154636723e6f40c35dc18cc4aa3ed33e5aa7fbc Mon Sep 17 00:00:00 2001 From: the_undefined Date: Wed, 16 Apr 2008 19:48:55 +0000 Subject: [PATCH] Added all-attribute selector support to Set::extract git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6669 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/set.php | 8 +++++++- cake/tests/cases/libs/set.test.php | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index de5b6fccf..65680d233 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -429,7 +429,13 @@ class Set extends Object { } $match = false; - if (array_key_exists($token, $context['item'])) { + if ($token == '@*' && is_array($context['item'])) { + $matches[] = array( + 'trace' => am($context['trace'], $key), + 'key' => $key, + 'item' => array_keys($context['item']), + ); + } elseif (is_array($context['item']) && array_key_exists($token, $context['item'])) { $items = $context['item'][$token]; if (!is_array($items) || !isset($items[0])) { $items = array($items); diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 07a4fc4f3..2fe5825f4 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -385,6 +385,10 @@ class SetTest extends UnitTestCase { $r = Set::extract('/User[id>1][id<=3]/id', $a); $this->assertEqual($r, $expected); + $expected = array(array('I'), array('II')); + $r = Set::extract('/a/@*', $c); + $this->assertEqual($r, $expected); + $single = array( 'User' => array( 'id' => 4, @@ -436,6 +440,10 @@ class SetTest extends UnitTestCase { $r = Set::extract('/User[name=/N/i]/id', $tricky); $this->assertEqual($r, $expected); + $expected = array(array('id', 'name'), array('id', 'name'), array('id', 'name'), array('id', 'name')); + $r = Set::extract('/User/@*', $tricky); + $this->assertEqual($r, $expected); + $common = array( array( 'Article' => array(