Convert array to change interface

@param array $changeData
@return ChangeInterface
490672
protected function convertChangeData($changeData)
    {
        $type = $changeData['type'];

        if (!isset($this->typeMap[$type])) {
            return new Error(sprintf('Could not convert change type %s, it is unknown to the system', $type));
        }

        $changeClass = $this->typeMap[$type];
        $changeClassInstance = $this->objectManager->get($changeClass);
        $changeClassInstance->injectPersistenceManager($this->persistenceManager);

        $subjectContextPath = $changeData['subject'];
        $subject = $this->nodeService->getNodeFromContextPath($subjectContextPath);

        if ($subject instanceof Error) {
            return $subject;
        }

        $changeClassInstance->setSubject($subject);

        if (isset($changeData['reference']) && method_exists($changeClassInstance, 'setReference')) {
            $referenceContextPath = $changeData['reference'];
            $reference = $this->nodeService->getNodeFromContextPath($referenceContextPath);

            if ($reference instanceof Error) {
                return $reference;
            }

            $changeClassInstance->setReference($reference);
        }

        if (isset($changeData['payload'])) {
            foreach ($changeData['payload'] as $propertyName => $value) {
                if (!in_array($propertyName, $this->disallowedPayloadProperties)) {
                    $methodParameters = $this->reflectionService->getMethodParameters($changeClass, ObjectAccess::buildSetterMethodName($propertyName));
                    $methodParameter = current($methodParameters);
                    $targetType = $methodParameter['type'];

                    // Fixme: The type conversion runs depending on the target node property type inside Property::class
                    // This is why we are not allowed to modify the value in any way.
                    // Without this condition the object was parsed to a string leading to fatal errors when changing images
                    // in the UI.
                    if ($propertyName !== 'value' && $targetType !== Property::class) {
                        $value = $this->propertyMapper->convert($value, $targetType);
                    }

                    ObjectAccess::setProperty($changeClassInstance, $propertyName, $value);
                }
            }
        }

        return $changeClassInstance;
    }
1086702
function createDifferenceObject( $fromData, $toData )
    {
        $changes = new eZXMLTextDiff();
        $contentINI = eZINI::instance( 'content.ini' );
        $useSimplifiedXML = $contentINI->variable( 'ContentVersionDiffSettings', 'UseSimplifiedXML' );
        $diffSimplifiedXML = ( $useSimplifiedXML == 'enabled' );

        $oldXMLTextObject = $fromData->content();
        $newXMLTextObject = $toData->content();

        $oldXML = $oldXMLTextObject->attribute( 'xml_data' );
        $newXML = $newXMLTextObject->attribute( 'xml_data' );

        $simplifiedXML = new eZSimplifiedXMLEditOutput();

        $domOld = new DOMDocument( '1.0', 'utf-8' );
        $domOld->preserveWhiteSpace = false;
        $domOld->loadXML( $oldXML );

        $domNew = new DOMDocument( '1.0', 'utf-8' );
        $domNew->preserveWhiteSpace = false;
        $domNew->loadXML( $newXML );

        $old = $simplifiedXML->performOutput( $domOld );
        $new = $simplifiedXML->performOutput( $domNew );

        if ( !$diffSimplifiedXML )
        {
            $old = trim( strip_tags( $old ) );
            $new = trim( strip_tags( $new ) );

            $pattern = array( '/[ ][ ]+/',
                              '/ \n( \n)+/',
                              '/^ /m',
                              '/(\n){3,}/' );
            $replace = array( ' ',
                              "\n",
                              '',
                              "\n\n" );

            $old = preg_replace( $pattern, $replace, $old );
            $new = preg_replace( $pattern, $replace, $new );
        }

        $oldArray = explode( "\n", $old );
        $newArray = explode( "\n", $new );

        $oldSums = array();
        foreach( $oldArray as $paragraph )
        {
            $oldSums[] = crc32( $paragraph );
        }

        $newSums = array();
        foreach( $newArray as $paragraph )
        {
            $newSums[] = crc32( $paragraph );
        }

        $textDiffer = new eZDiffTextEngine();

        $pre = $textDiffer->preProcess( $oldSums, $newSums );
        $out = $textDiffer->createOutput( $pre, $oldArray, $newArray );
        $changes->setChanges( $out );
        return $changes;
    }
750941
public function appendArray(array $arrayData)
    {
        foreach ($arrayData as $dataKey => $data) {
            $this->_putData($dataKey, $data);
        }

        if ($this->_objectCreation) {
            return $this->_afterAppendDataToNewObject();
        }
        return $this;
    }
679371
function &diff( $fromData, $toData)
    {
        if ( !$this->DiffEngineInstance )
            return null;

        $differ =& $this->DiffEngineInstance;
        $diffObject = $differ->createDifferenceObject( $fromData, $toData );
        return $diffObject;
    }
1156284
public function exchangeArray($data)
    {
        foreach($data as $prop => $value) {
            $methodName = 'set' . ucfirst($prop);
            if(method_exists ($this, $methodName)) {
                call_user_func(array($this, $methodName), $value);
            }
        }
    }
1129707
public function dataUpload($fileData)
    {
        $target = parent::dataUpload($fileData);

        if ($this->applyEffects('upload')) {
            $target = $this->processEffects($target);
        }

        return $target;
    }
1059422
public function setData($modelData)
    {
        if ($this->config->getInheritData()) {
            throw new RuntimeException('You cannot change the data of a block inheriting its parent data.');
        }

        if ($this->lockSetData) {
            throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the BlockEvent object instead.');
        }

        if (null !== $this->getForm() && null === $this->getForm()->getData()) {
            $this->getForm()->setData($modelData);
        }

        $this->lockSetData = true;
        $dispatcher = $this->config->getEventDispatcher();

        // Hook to change content of the data
        if ($dispatcher->hasListeners(BlockEvents::PRE_SET_DATA)) {
            $event = new BlockEvent($this, $modelData);
            $dispatcher->dispatch(BlockEvents::PRE_SET_DATA, $event);
            $modelData = $event->getData();
        }

        if (BlockUtil::isEmpty($modelData)) {
            $emptyData = $this->config->getEmptyData();

            if ($emptyData instanceof \Closure) {
                /* @var \Closure $emptyData */
                $emptyData = $emptyData($this, $modelData, $this->getOptions());
            }

            $modelData = $emptyData;
        }

        // Treat data as strings unless a value transformer exists
        if (!$this->config->getViewTransformers() && !$this->config->getModelTransformers() && is_scalar($modelData) && !\is_bool($modelData)) {
            $modelData = (string) $modelData;
        }

        // Synchronize representations - must not change the content!
        $normData = $this->modelToNorm($modelData);
        $viewData = $this->normToView($normData);

        // Validate if view data matches data class (unless empty)
        if (!BlockUtil::isEmpty($viewData)) {
            $dataClass = $this->getDataClass();

            $actualType = \is_object($viewData) ? 'an instance of class '.\get_class($viewData) : ' a(n) '.\gettype($viewData);

            if (null === $dataClass && \is_object($viewData) && !$viewData instanceof \ArrayAccess) {
                $expectedType = 'scalar, array or an instance of \ArrayAccess';

                throw new LogicException(
                        'The block\'s view data is expected to be of type '.$expectedType.', '.
                        'but is '.$actualType.'. You '.
                        'can avoid this error by setting the "data_class" option to '.
                        '"'.\get_class($viewData).'" or by adding a view transformer '.
                        'that transforms '.$actualType.' to '.$expectedType.'.'
                );
            }

            if (null !== $dataClass && !$viewData instanceof $dataClass) {
                throw new LogicException(
                        'The block\'s view data is expected to be an instance of class '.
                        $dataClass.', but is '.$actualType.'. You can avoid this error '.
                        'by setting the "data_class" option to null or by adding a view '.
                        'transformer that transforms '.$actualType.' to an instance of '.
                        $dataClass.'.'
                );
            }
        } else {
            $viewData = (string) $this->config->getEmptyMessage();
        }

        $this->modelData = $modelData;
        $this->normData = $normData;
        $this->viewData = $viewData;
        $this->defaultDataSet = true;
        $this->lockSetData = false;

        if (\count($this->children) > 0) {
            $childrenIterator = new InheritDataAwareIterator($this->children);
            $childrenIterator = new \RecursiveIteratorIterator($childrenIterator);
            $this->config->getDataMapper()->mapDataToViews($viewData, $childrenIterator);
        }

        if ($dispatcher->hasListeners(BlockEvents::POST_SET_DATA)) {
            $event = new BlockEvent($this, $modelData);
            $dispatcher->dispatch(BlockEvents::POST_SET_DATA, $event);
        }

        return $this;
    }
1133409
public function update($changeItemContent = false)
    {
        $returnValue = array();
        $objects     = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->itemPath), RecursiveIteratorIterator::SELF_FIRST);
        $i = 0;
        $fixed = 0;
        
        foreach ($objects as $itemFile => $cursor) {

            if (is_file($itemFile)) {
                
                $this->checkedFiles[$itemFile] = false;

                if (basename($itemFile) === 'qti.xml') {

                    $i++;
                    $xml = new \DOMDocument();
                    $xml->load($itemFile);

                    $parser = new ParserFactory($xml);
                    $item   = $parser->load();
                    \common_Logger::i('checking item #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile);

                    if ($this->updateItem($item, $itemFile)) {
                        $this->checkedFiles[$itemFile] = true;
                        $returnValue[$itemFile]        = $item;
                        \common_Logger::i('fixed required for #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile);
                        if ($changeItemContent) {
                            $fixed++;
                            \common_Logger::i('item fixed #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile);
                            file_put_contents($itemFile, $item->toXML());
                        }
                    }
                }
            }
        }

        \common_Logger::i('total item fixed : '.$fixed);
        return $returnValue;
    }
425441
public function fileUpload(array $fileData)
    {
        $target = parent::fileUpload($fileData);

        if ($this->applyEffects('upload')) {
            $target = $this->processEffects($target);
        }

        return $target;
    }
555268
public function setData(array $data)
    {
        if (isset($data['attachables'])) {
            $this->setAttachables($data['attachables']);
        }

        if (isset($data['groups'])) {
            $this->setGroups($data['groups']);
        }

        if (isset($data['widgets'])) {
            $this->setWidgets($data['widgets']);
        }

        unset($data['attachables'], $data['groups'], $data['widgets']);

        return parent::setData($data);
    }
1288732
public function setData(array $data) {
		$this->data = $data;

		$this->resetFields();

		foreach($data as $name=>$data)
			$this->newField($name, $data);

		$this->updateChilds();

		return $this;
	}
1068137
protected function convertToResource($data)
    {
        return Collection::make($this->client, $data->id)
            ->init($data);
    }
663430
protected function dereferenceArray(array &$arrayData)
    {
        try {
            foreach ($arrayData as $idx => $data) {
                // go deeper if is array
                if (is_array($data)) {
                    $this->dereferenceArray($arrayData[$idx]);

                // dereference if it is a reference #changed
                } elseif (false !== ($ref = $this->isReference($data))) {
                    $arrayData[$idx] = $this->getReferenceValue($ref);
                }
            }
        } catch (\Exception $e) {
            throw new LogicException($e->getMessage(), $e->getCode(), $e);
        }
    }
305486
public function mergeData($data, $overridePrevious = true)
    {
        $oldData = $this->getData();
        if ($oldData === null) {
            $oldData = [];
        }
        if (is_object($data)) {
            $data = get_object_vars($data);
        }
        $this->setData($overridePrevious ? array_merge($oldData, $data) : array_merge($data, $oldData));
        return $this;
    }
1065862
public function setContents(array $data)
	{
		if ($this->readOnly)
		{
			throw new \RuntimeException('Changing values on this Data Container is not allowed.');
		}

		$this->data = $data;

		$this->isModified = true;

		return $this;
	}
1269249
private function getChanges(array $data)
    {
        $changes = [
            'inserted' => Arr::dot($data),
            'updated'  => [],
            'deleted'  => [],
        ];

        foreach ($this->newQuery()->pluck($this->keyColumn) as $key) {
            if (Arr::has($changes['inserted'], $key))
                $changes['updated'][$key] = $changes['inserted'][$key];
            else
                $changes['deleted'][] = $key;

            Arr::forget($changes['inserted'], $key);
        }

        return $changes;
    }
333084
protected function transformDataForRepository($modelData)
    {
        foreach ($this->columnTransforms as $columnName => $transforms) {
            if ($transforms[1] !== null) {
                $closure = $transforms[1];

                $transformedData = $closure($modelData);

                if (is_array($transformedData)) {
                    // If the original value is to be retained, the transform function should
                    // explicitly return it - in other cases we need to unset it here.
                    unset($modelData[$columnName]);

                    $modelData = array_merge($modelData, $transformedData);
                } else {
                    $modelData[$columnName] = $transformedData;
                }
            }
        }

        return $modelData;
    }