convertFrom() 공개 메소드

The return value can be one of three types: - an arbitrary object, or a simple type (which has been created while mapping). This is the normal case. - NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur. - An instance of \Neos\Error\Messages\Error -- This will be a user-visible error message later on. Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened.
public convertFrom ( array $source, string $targetType = 'array', array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : array
$source array
$targetType string
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
리턴 array the target type, or an error object if a user-error occurred
 /**
  * Converts and adds ImageAdjustments to the ImageVariant
  *
  * @param ImageInterface $asset
  * @param mixed $source
  * @param array $convertedChildProperties
  * @param PropertyMappingConfigurationInterface $configuration
  * @return ImageInterface|NULL
  */
 protected function applyTypeSpecificHandling($asset, $source, array $convertedChildProperties, PropertyMappingConfigurationInterface $configuration)
 {
     if ($asset instanceof ImageVariant) {
         $adjustments = [];
         if (isset($source['adjustments'])) {
             foreach ($source['adjustments'] as $adjustmentType => $adjustmentOptions) {
                 if (isset($adjustmentOptions['__type'])) {
                     $adjustmentType = $adjustmentOptions['__type'];
                     unset($adjustmentOptions['__type']);
                 }
                 $identity = null;
                 if (isset($adjustmentOptions['__identity'])) {
                     $identity = $adjustmentOptions['__identity'];
                     unset($adjustmentOptions['__identity']);
                 }
                 $adjustment = $this->propertyMapper->convert($adjustmentOptions, $adjustmentType, $configuration);
                 if ($identity !== null) {
                     ObjectAccess::setProperty($adjustment, 'persistence_object_identifier', $identity, true);
                 }
                 $adjustments[] = $adjustment;
             }
         } elseif (isset($source['processingInstructions'])) {
             $adjustments = $this->processingInstructionsConverter->convertFrom($source['processingInstructions'], 'array');
         }
         if (count($adjustments) > 0) {
             $asset->addAdjustments($adjustments);
         }
     }
     return $asset;
 }
 /**
  * Change the property on the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) {
         if (isset($propertyConfiguration['type']) && ($propertyConfiguration['type'] === ImageInterface::class || preg_match('/array\\<.*\\>/', $propertyConfiguration['type']))) {
             if (!isset($nodeProperties)) {
                 $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?');
                 $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]);
                 $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC);
                 $nodeProperties = unserialize($nodeRecord['properties']);
             }
             if (!isset($nodeProperties[$propertyName]) || empty($nodeProperties[$propertyName])) {
                 continue;
             }
             if ($propertyConfiguration['type'] === ImageInterface::class) {
                 $adjustments = array();
                 $oldVariantConfiguration = $nodeProperties[$propertyName];
                 if (is_array($oldVariantConfiguration)) {
                     foreach ($oldVariantConfiguration as $variantPropertyName => $property) {
                         switch (substr($variantPropertyName, 3)) {
                             case 'originalImage':
                                 /**
                                  * @var $originalAsset Image
                                  */
                                 $originalAsset = $this->assetRepository->findByIdentifier($this->persistenceManager->getIdentifierByObject($property));
                                 break;
                             case 'processingInstructions':
                                 $adjustments = $this->processingInstructionsConverter->convertFrom($property, 'array');
                                 break;
                         }
                     }
                     $nodeProperties[$propertyName] = null;
                     if (isset($originalAsset)) {
                         $stream = $originalAsset->getResource()->getStream();
                         if ($stream === false) {
                             continue;
                         }
                         fclose($stream);
                         $newImageVariant = new ImageVariant($originalAsset);
                         foreach ($adjustments as $adjustment) {
                             $newImageVariant->addAdjustment($adjustment);
                         }
                         $originalAsset->addVariant($newImageVariant);
                         $this->assetRepository->update($originalAsset);
                         $nodeProperties[$propertyName] = $this->persistenceManager->getIdentifierByObject($newImageVariant);
                     }
                 }
             } elseif (preg_match('/array\\<.*\\>/', $propertyConfiguration['type'])) {
                 if (is_array($nodeProperties[$propertyName])) {
                     $convertedValue = [];
                     foreach ($nodeProperties[$propertyName] as $entryValue) {
                         if (!is_object($entryValue)) {
                             continue;
                         }
                         $stream = $entryValue->getResource()->getStream();
                         if ($stream === false) {
                             continue;
                         }
                         fclose($stream);
                         $existingObjectIdentifier = null;
                         try {
                             $existingObjectIdentifier = $this->persistenceManager->getIdentifierByObject($entryValue);
                             if ($existingObjectIdentifier !== null) {
                                 $convertedValue[] = $existingObjectIdentifier;
                             }
                         } catch (\Exception $exception) {
                         }
                     }
                     $nodeProperties[$propertyName] = $convertedValue;
                 }
             }
         }
     }
     if (isset($nodeProperties)) {
         $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?');
         $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]);
     }
 }