Cake\ElasticSearch\Marshaller::mergeMany PHP Méthode

mergeMany() public méthode

Merges each of the elements from $data into each of the entities in $entities. Records in $data are matched against the entities using the id field. Entries in $entities that cannot be matched to any record in $data will be discarded. Records in $data that could not be matched will be marshalled as a new entity. ### 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.
public mergeMany ( array $entities, array $data, array $options = [] ) : array
$entities array An array of Elasticsearch entities
$data array A list of entity data you want converted into objects.
$options array Options
Résultat array An array of merged entities
    public function mergeMany(array $entities, array $data, array $options = [])
    {
        $indexed = (new Collection($data))->groupBy('id')->map(function ($element, $key) {
            return $key === '' ? $element : $element[0];
        })->toArray();
        $new = isset($indexed[null]) ? $indexed[null] : [];
        unset($indexed[null]);
        $output = [];
        foreach ($entities as $record) {
            if (!$record instanceof EntityInterface) {
                continue;
            }
            $id = $record->id;
            if (!isset($indexed[$id])) {
                continue;
            }
            $output[] = $this->merge($record, $indexed[$id], $options);
            unset($indexed[$id]);
        }
        $new = array_merge($indexed, $new);
        foreach ($new as $newRecord) {
            $output[] = $this->one($newRecord, $options);
        }
        return $output;
    }