lithium\data\source\mongo_db\Exporter::_append()
Handles appending nested objects to document changesets.
Parameters
-
array
$changes
The full set of changes to be made to the database.
-
string
$key
The key of the field to append, which may be a dot-separated path if the value is or is contained within a nested object.
-
mixed
$value
The value to append to the changeset. Can be a scalar value, array, a nested object, or part of a nested object.
-
string
$change
The type of change, as to whether update/remove or rename etc.
Returns
arrayReturns the value of $changes
, with any new changed values appended.
Source
protected static function _append($changes, $key, $value, $change) {
$options = ['finalize' => false];
if (!is_object($value) || !method_exists($value, 'export')) {
$changes[$change][$key] = ($change === 'update') ? $value : true;
return $changes;
}
if (!$value->exists()) {
$changes[$change][$key] = static::_create($value->export(), $options);
return $changes;
}
if ($change === 'update') {
$export = compact('key') + $value->export();
return Set::merge($changes, static::_update($export));
}
if ($children = static::_update($value->export())) {
return Set::merge($changes, $children);
}
$changes[$change][$key] = true;
return $changes;
}