lithium\data\source\mongo_db\Exporter::_append PHP Method

_append() protected static method

Handles appending nested objects to document changesets.
protected static _append ( array $changes, string $key, mixed $value, string $change ) : array
$changes array The full set of changes to be made to the database.
$key string 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.
$value mixed The value to append to the changeset. Can be a scalar value, array, a nested object, or part of a nested object.
$change string The type of change, as to whether update/remove or rename etc.
return array Returns the value of `$changes`, with any new changed values appended.
    protected static function _append($changes, $key, $value, $change)
    {
        $options = array('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;
    }