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
This commit is contained in:
the_undefined 2008-04-16 19:48:55 +00:00
parent fc8611b003
commit c154636723
2 changed files with 15 additions and 1 deletions

View file

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

View file

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