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

findTypeConverter() protected method

Determine the type converter to be used. If no converter has been found, an exception is raised.
protected findTypeConverter ( mixed $source, string $targetType, Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration ) : Neos\Flow\Property\TypeConverterInterface
$source mixed
$targetType string
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
return Neos\Flow\Property\TypeConverterInterface Type Converter which should be used to convert between $source and $targetType.
    protected function findTypeConverter($source, $targetType, PropertyMappingConfigurationInterface $configuration)
    {
        if ($configuration->getTypeConverter() !== null) {
            return $configuration->getTypeConverter();
        }
        if (!is_string($targetType)) {
            throw new Exception\InvalidTargetException('The target type was no string, but of type "' . gettype($targetType) . '"', 1297941727);
        }
        $normalizedTargetType = TypeHandling::normalizeType($targetType);
        $truncatedTargetType = TypeHandling::truncateElementType($normalizedTargetType);
        $converter = null;
        $sourceTypes = $this->determineSourceTypes($source);
        foreach ($sourceTypes as $sourceType) {
            if (TypeHandling::isSimpleType($truncatedTargetType)) {
                if (isset($this->typeConverters[$sourceType][$truncatedTargetType])) {
                    $converter = $this->findEligibleConverterWithHighestPriority($this->typeConverters[$sourceType][$truncatedTargetType], $source, $normalizedTargetType);
                }
            } else {
                $converter = $this->findFirstEligibleTypeConverterInObjectHierarchy($source, $sourceType, $normalizedTargetType);
            }
            if ($converter !== null) {
                return $converter;
            }
        }
        throw new Exception\TypeConverterException('No converter found which can be used to convert from "' . implode('" or "', $sourceTypes) . '" to "' . $normalizedTargetType . '".');
    }