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 . '".');
}