mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Added support for dot char (selecting the current context node)
Fixed some more issues and added more tests git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6660 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
9f040bd395
commit
4679dc9a12
2 changed files with 15 additions and 3 deletions
|
@ -423,7 +423,7 @@ class Set extends Object {
|
|||
$matches[] = $context;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$match = false;
|
||||
if (array_key_exists($token, $context['item'])) {
|
||||
$items = $context['item'][$token];
|
||||
|
@ -441,7 +441,7 @@ class Set extends Object {
|
|||
'item' => $item,
|
||||
);
|
||||
}
|
||||
} else if ($key === $token && (!$conditions || Set::matches($conditions, $context['item'], $i+1))) {
|
||||
} elseif (($key === $token || (ctype_digit($token) && $key == $token) || $token === '.') && (!$conditions || Set::matches($conditions, $context['item'], $i))) {
|
||||
$matches[] = array(
|
||||
'trace' => am($context['trace'], $key),
|
||||
'key' => $key,
|
||||
|
@ -457,7 +457,7 @@ class Set extends Object {
|
|||
|
||||
$r = array();
|
||||
foreach ($matches as $match) {
|
||||
if (!$options['flatten'] || is_array($match['item'])) {
|
||||
if ((!$options['flatten'] || is_array($match['item'])) && !is_int($match['key'])) {
|
||||
$r[] = array($match['key'] => $match['item']);
|
||||
} else {
|
||||
$r[] = $match['item'];
|
||||
|
|
|
@ -494,6 +494,18 @@ class SetTest extends UnitTestCase {
|
|||
$expected = array(1, 2, 4, 5);
|
||||
$r = Set::extract($common, '/Comment[id!=3]/id');
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
$expected = array($common[0]['Comment'][2]);
|
||||
$r = Set::extract($common, '/Comment/2');
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
$expected = array($common[0]['Comment'][1]);
|
||||
$r = Set::extract($common, '/Comment[1]/.[id=2]');
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
$expected = array($common[0]['Comment'][1]);
|
||||
$r = Set::extract($common, '/Comment[1]/.[2]');
|
||||
$this->assertEqual($r, $expected);
|
||||
}
|
||||
/**
|
||||
* undocumented function
|
||||
|
|
Loading…
Reference in a new issue