Neos\Flow\Property\PropertyMapper::convert PHP Method

convert() public method

If $source is an object and already is of type $targetType, we do return the unmodified object.
public convert ( mixed $source, string $targetType, Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : mixed
$source mixed the source data to map. MUST be a simple type, NO object allowed!
$targetType string The type of the target; can be either a class name or a simple type.
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface Configuration for the property mapping. If NULL, the PropertyMappingConfigurationBuilder will create a default configuration.
return mixed an instance of $targetType
    public function convert($source, $targetType, PropertyMappingConfigurationInterface $configuration = null)
    {
        if ($configuration === null) {
            $configuration = $this->buildPropertyMappingConfiguration();
        }
        $currentPropertyPath = [];
        $this->messages = new Result();
        try {
            $result = $this->doMapping($source, $targetType, $configuration, $currentPropertyPath);
            if ($result instanceof Error) {
                return null;
            }
            return $result;
        } catch (SecurityException $exception) {
            throw $exception;
        } catch (\Exception $exception) {
            throw new PropertyException('Exception while property mapping for target type "' . $targetType . '", at property path "' . implode('.', $currentPropertyPath) . '": ' . $exception->getMessage(), 1297759968, $exception);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Returns a previously uploaded image.
  * If errors occurred during property mapping for this property, NULL is returned
  *
  * @return Image
  */
 protected function getUploadedImage()
 {
     if ($this->getMappingResultsForProperty()->hasErrors()) {
         return null;
     }
     $image = $this->getValue(false);
     if ($image instanceof Image) {
         return $image;
     }
     return $this->propertyMapper->convert($image, Image::class);
 }
All Usage Examples Of Neos\Flow\Property\PropertyMapper::convert