mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 10:36:16 +00:00
Fixed issues with Set::extract and multiple numerically indexed nestings
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6656 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
c38c6a21ba
commit
593c4d7245
2 changed files with 66 additions and 10 deletions
|
@ -418,22 +418,25 @@ class Set extends Object {
|
|||
|
||||
$match = false;
|
||||
if (array_key_exists($token, $context['item']) && (!$conditions || Set::matches($conditions, $context['item'][$token], $i))) {
|
||||
$match = array(
|
||||
'trace' => am($context['trace'], $context['key']),
|
||||
'key' => $token,
|
||||
'item' => $context['item'][$token],
|
||||
);
|
||||
$items = $context['item'][$token];
|
||||
if (!is_array($items) || !isset($items[0])) {
|
||||
$items = array($items);
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$matches[] = array(
|
||||
'trace' => am($context['trace'], $context['key']),
|
||||
'key' => $token,
|
||||
'item' => $item,
|
||||
);
|
||||
}
|
||||
} else if ($key === $token && (!$conditions || Set::matches($conditions, $context['item'], $i+1))) {
|
||||
$match = array(
|
||||
$matches[] = array(
|
||||
'trace' => am($context['trace'], $key),
|
||||
'key' => $key,
|
||||
'item' => $context['item'],
|
||||
);
|
||||
}
|
||||
|
||||
if ($match) {
|
||||
$matches[] = $match;
|
||||
}
|
||||
}
|
||||
if (empty($tokens)) {
|
||||
break;
|
||||
|
|
|
@ -423,6 +423,59 @@ class SetTest extends UnitTestCase {
|
|||
$expected = array(4);
|
||||
$r = Set::extract('/User/id', $single);
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
$common = array(
|
||||
array(
|
||||
'Article' => array(
|
||||
'id' => 1,
|
||||
'name' => 'Article 1',
|
||||
),
|
||||
'Comment' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'user_id' => 5,
|
||||
'article_id' => 1,
|
||||
'text' => 'Comment 1',
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'user_id' => 23,
|
||||
'article_id' => 1,
|
||||
'text' => 'Comment 2',
|
||||
),
|
||||
array(
|
||||
'id' => 3,
|
||||
'user_id' => 17,
|
||||
'article_id' => 1,
|
||||
'text' => 'Comment 3',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Article' => array(
|
||||
'id' => 2,
|
||||
'name' => 'Article 2',
|
||||
),
|
||||
'Comment' => array(
|
||||
array(
|
||||
'id' => 4,
|
||||
'user_id' => 2,
|
||||
'article_id' => 2,
|
||||
'text' => 'Comment 4',
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'user_id' => 3,
|
||||
'article_id' => 2,
|
||||
'text' => 'Comment 5',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$r = Set::extract('/Comment/id', $common);
|
||||
$expected = array(1, 2, 3, 4, 5);
|
||||
$this->assertEqual($r, $expected);
|
||||
}
|
||||
/**
|
||||
* undocumented function
|
||||
|
|
Loading…
Add table
Reference in a new issue