Cake\ElasticSearch\Marshaller::newNested PHP Method

newNested() protected method

Marshal an embedded document.
protected newNested ( Embedded $embed, array $data ) : array | Document
$embed Cake\ElasticSearch\Association\Embedded The embed definition.
$data array The data to marshal
return array | Document Either a document or an array of documents.
    protected function newNested(Embedded $embed, array $data)
    {
        $class = $embed->entityClass();
        if ($embed->type() === Embedded::ONE_TO_ONE) {
            return new $class($data);
        }
        if ($embed->type() === Embedded::ONE_TO_MANY) {
            $children = [];
            foreach ($data as $row) {
                if (is_array($row)) {
                    $children[] = new $class($row);
                }
            }
            return $children;
        }
    }