Doctrine\ODM\CouchDB\Mapping\EmbeddedDocumentSerializer::doCreateEmbeddedDocument PHP Method

doCreateEmbeddedDocument() public method

public doCreateEmbeddedDocument ( $data, $embeddedFieldMapping )
    public function doCreateEmbeddedDocument($data, $embeddedFieldMapping)
    {
        if (!$this->metadataResolver->canMapDocument($data)) {
            if (!isset($embeddedFieldMapping['targetDocument'])) {
                throw new \InvalidArgumentException("Missing or missmatching metadata description in the EmbeddedDocument, cannot hydrate!");
            }
            $type = $embeddedFieldMapping['targetDocument'];
        } else {
            $type = $this->metadataResolver->getDocumentType($data);
        }
        $class = $this->metadataFactory->getMetadataFor($type);
        $instance = $class->newInstance();
        $documentState = array();
        foreach ($data as $jsonName => $jsonValue) {
            if ($this->metadataResolver->canResolveJsonField($jsonName)) {
                continue;
            }
            if (isset($class->jsonNames[$jsonName])) {
                $fieldName = $class->jsonNames[$jsonName];
                if (isset($class->fieldMappings[$fieldName])) {
                    if ($jsonValue === null) {
                        $fieldValue = null;
                    } else {
                        if (isset($class->fieldMappings[$fieldName]['embedded'])) {
                            $fieldValue = $this->createEmbeddedDocument($jsonValue, $class->fieldMappings[$fieldName]);
                        } else {
                            $fieldValue = Type::getType($class->fieldMappings[$fieldName]['type'])->convertToPHPValue($jsonValue);
                        }
                    }
                    $class->setFieldValue($instance, $class->fieldMappings[$fieldName]['fieldName'], $fieldValue);
                }
            } else {
                //$nonMappedData[$jsonName] = $jsonValue;
            }
        }
        return $instance;
    }