Cake\ElasticSearch\Marshaller::merge PHP Method

merge() public method

### Options: * fieldList: A whitelist of fields to be assigned to the entity. If not present the accessible fields list in the entity will be used. * associated: A list of embedded documents you want to marshal.
public merge ( Cake\Datasource\EntityInterface $entity, array $data, array $options = [] ) : Cake\Datasource\EntityInterface
$entity Cake\Datasource\EntityInterface the entity that will get the data merged in
$data array key value list of fields to be merged into the entity
$options array List of options.
return Cake\Datasource\EntityInterface
    public function merge(EntityInterface $entity, array $data, array $options = [])
    {
        $options += ['associated' => []];
        list($data, $options) = $this->_prepareDataAndOptions($data, $options);
        $errors = $this->_validate($data, $options, $entity->isNew());
        $entity->errors($errors);
        foreach (array_keys($errors) as $badKey) {
            unset($data[$badKey]);
        }
        foreach ($this->type->embedded() as $embed) {
            $property = $embed->property();
            if (in_array($embed->alias(), $options['associated']) && isset($data[$property])) {
                $data[$property] = $this->mergeNested($embed, $entity->{$property}, $data[$property]);
            }
        }
        if (!isset($options['fieldList'])) {
            $entity->set($data);
            return $entity;
        }
        foreach ((array) $options['fieldList'] as $field) {
            if (array_key_exists($field, $data)) {
                $entity->set($field, $data[$field]);
            }
        }
        return $entity;
    }