lithium\g11n\catalog\Adapter::_merge()
Merges an item into given data.
Parameters
-
array
$data
Data to merge item into.
-
array
$item
Item to merge into $data. The item must have an
'id'
key.
Returns
arrayThe merged data.
Source
protected function _merge(array $data, array $item) {
if (!isset($item['id'])) {
return $data;
}
$id = $item['id'];
$defaults = [
'ids' => [],
'translated' => null,
'flags' => [],
'comments' => [],
'occurrences' => []
];
$item += $defaults;
if (isset($item['context']) && $item['context']) {
$id .= '|' . $item['context'];
}
if (!isset($data[$id])) {
$data[$id] = $item;
return $data;
}
foreach (['ids', 'flags', 'comments', 'occurrences'] as $field) {
$data[$id][$field] = array_merge($data[$id][$field], $item[$field]);
}
if (!isset($data[$id]['translated'])) {
$data[$id]['translated'] = $item['translated'];
} elseif (is_array($item['translated'])) {
$data[$id]['translated'] = (array) $data[$id]['translated'] + $item['translated'];
}
return $data;
}