Doctrine\ODM\CouchDB\Mapping\EmbeddedDocumentSerializer::isChanged PHP Метод

isChanged() публичный Метод

If the original misses doctrine_metadata, but the values are the same, we assume there is no change If the original has doctrine_metadata, and the new value has different class, that's a change, even if the values are the same.
public isChanged ( array $value, object $originalData, array $valueFieldMapping ) : boolean
$value array
$originalData object
$valueFieldMapping array Mapping of the field that contains the embedded document in the embedder document.
Результат boolean
    public function isChanged($value, $originalData, $valueFieldMapping)
    {
        // EmbedMany case
        if ('many' == $valueFieldMapping['embedded'] && (is_array($value) || $value instanceof \Doctrine\Common\Collections\ArrayCollection)) {
            if (count($originalData) != count($value)) {
                return true;
            }
            foreach ($value as $key => $valueElement) {
                if (!isset($originalData[$key]) || $this->isChanged($valueElement, $originalData[$key], $valueFieldMapping)) {
                    return true;
                }
            }
            return false;
        }
        // EmbedOne case, or one instance of and EmbedMany
        if ($this->metadataResolver->canMapDocument($originalData) && get_class($value) !== $this->metadataResolver->getDocumentType($originalData)) {
            return true;
        }
        $class = $this->metadataFactory->getMetadataFor(get_class($value));
        foreach ($class->reflFields as $fieldName => $fieldValue) {
            $fieldMapping = $class->fieldMappings[$fieldName];
            $originalDataValue = isset($originalData[$fieldMapping['jsonName']]) ? $originalData[$fieldMapping['jsonName']] : null;
            $currentValue = $class->getFieldValue($value, $fieldMapping['fieldName']);
            if ($originalDataValue === null && $currentValue === null) {
                continue;
            } else {
                if ($originalDataValue === null || $currentValue === null) {
                    return true;
                }
            }
            if (!isset($fieldMapping['embedded'])) {
                // simple property comparison
                // TODO this conversion could be avoided if we store the php value in the original data
                //      as with the simple property mapping in UOW.
                $originalValue = Type::getType($fieldMapping['type'])->convertToPHPValue($originalDataValue);
                if ($originalValue != $currentValue) {
                    return true;
                }
            } else {
                if ('many' == $fieldMapping['embedded']) {
                    if (count($originalDataValue) != count($currentValue)) {
                        return true;
                    }
                    foreach ($currentValue as $currentKey => $currentElem) {
                        if (!isset($originalDataValue[$currentKey])) {
                            return true;
                        }
                        if ($this->isChanged($currentElem, $originalDataValue[$currentKey], $fieldMapping)) {
                            return true;
                        }
                    }
                } else {
                    // embedOne
                    if ($this->isChanged($currentValue, $originalDataValue, $fieldMapping)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }