75 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'extbase'][
'typeConverters'] as $typeConverterClassName) {
76 $typeConverter = $this->objectManager->get($typeConverterClassName);
77 foreach ($typeConverter->getSupportedSourceTypes() as $supportedSourceType) {
78 if (isset($this->typeConverters[$supportedSourceType][$typeConverter->getSupportedTargetType()][$typeConverter->getPriority()])) {
79 throw new \TYPO3\CMS\Extbase\Property\Exception\DuplicateTypeConverterException(
'There exist at least two converters which handle the conversion from "' . $supportedSourceType .
'" to "' . $typeConverter->getSupportedTargetType() .
'" with priority "' . $typeConverter->getPriority() .
'": ' . get_class($this->typeConverters[$supportedSourceType][$typeConverter->getSupportedTargetType()][$typeConverter->getPriority()]) .
' and ' . get_class($typeConverter), 1297951378);
81 $this->typeConverters[$supportedSourceType][$typeConverter->getSupportedTargetType()][$typeConverter->getPriority()] = $typeConverter;
97 if ($configuration === NULL) {
98 $configuration = $this->configurationBuilder->build();
100 $currentPropertyPath = array();
101 $this->messages = new \TYPO3\CMS\Extbase\Error\Result();
103 $result = $this->
doMapping($source, $targetType, $configuration, $currentPropertyPath);
104 if (
$result instanceof \
TYPO3\CMS\Extbase\Error\Error) {
112 throw new \TYPO3\CMS\Extbase\Property\Exception(
'Exception while property mapping at property path "' . implode(
'.', $currentPropertyPath) .
'":' . $e->getMessage(), 1297759968, $e);
137 if (is_object($source)) {
139 if ($source instanceof $targetType) {
144 if ($source === NULL) {
149 $targetType = $typeConverter->getTargetTypeForSource($source, $targetType, $configuration);
152 throw new \TYPO3\CMS\Extbase\Property\Exception\TypeConverterException(
'Type converter for "' . $source .
'" -> "' . $targetType .
'" not found.');
155 $convertedChildProperties = array();
156 foreach ($typeConverter->getSourceChildPropertiesToBeConverted($source) as $sourcePropertyName => $sourcePropertyValue) {
157 $targetPropertyName = $configuration->getTargetPropertyName($sourcePropertyName);
158 if ($configuration->shouldSkip($targetPropertyName)) {
162 if (!$configuration->shouldMap($targetPropertyName)) {
163 if ($configuration->shouldSkipUnknownProperties()) {
166 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidPropertyMappingConfigurationException(
'It is not allowed to map property "' . $targetPropertyName .
'". You need to use $propertyMappingConfiguration->allowProperties(\'' . $targetPropertyName .
'\') to enable mapping of
this property.
', 1355155913); 169 $targetPropertyType = $typeConverter->getTypeOfChildProperty($targetType, $targetPropertyName, $configuration); 171 $subConfiguration = $configuration->getConfigurationFor($targetPropertyName); 173 $currentPropertyPath[] = $targetPropertyName; 174 $targetPropertyValue = $this->doMapping($sourcePropertyValue, $targetPropertyType, $subConfiguration, $currentPropertyPath); 175 array_pop($currentPropertyPath); 176 if (!($targetPropertyValue instanceof \TYPO3\CMS\Extbase\Error\Error)) { 177 $convertedChildProperties[$targetPropertyName] = $targetPropertyValue; 180 $result = $typeConverter->convertFrom($source, $targetType, $convertedChildProperties, $configuration); 182 if ($result instanceof \TYPO3\CMS\Extbase\Error\Error) { 183 $this->messages->forProperty(implode('.
', $currentPropertyPath))->addError($result); 199 protected function findTypeConverter($source, $targetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration) { 200 if ($configuration->getTypeConverter() !== NULL) { 201 return $configuration->getTypeConverter(); 204 $sourceType = $this->determineSourceType($source); 206 if (!is_string($targetType)) { 207 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('The target type was no string, but of type
"' . gettype($targetType) . '"', 1297941727); 210 $targetType = $this->parseCompositeType($targetType); 211 // This is needed to correctly convert old class names to new ones 212 // This compatibility layer will be removed with 7.0 213 $targetType = \TYPO3\CMS\Core\Core\ClassLoader::getClassNameForAlias($targetType); 215 $targetType = TypeHandlingUtility::normalizeType($targetType); 219 if (TypeHandlingUtility::isSimpleType($targetType)) { 220 if (isset($this->typeConverters[$sourceType][$targetType])) { 221 $converter = $this->findEligibleConverterWithHighestPriority($this->typeConverters[$sourceType][$targetType], $source, $targetType); 224 $converter = $this->findFirstEligibleTypeConverterInObjectHierarchy($source, $sourceType, $targetType); 227 if ($converter === NULL) { 228 throw new \TYPO3\CMS\Extbase\Property\Exception\TypeConverterException('No converter found which can be used to
convert from
"' . $sourceType . '" to
"' . $targetType . '".
'); 243 protected function findFirstEligibleTypeConverterInObjectHierarchy($source, $sourceType, $targetClass) { 244 if (!class_exists($targetClass) && !interface_exists($targetClass)) { 245 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Could not find a suitable type converter
for "' . $targetClass . '" because no such
class or interface exists.', 1297948764);
248 if (!isset($this->typeConverters[$sourceType])) {
252 $convertersForSource = $this->typeConverters[$sourceType];
253 if (isset($convertersForSource[$targetClass])) {
255 if ($converter !== NULL) {
260 foreach (class_parents($targetClass) as $parentClass) {
261 if (!isset($convertersForSource[$parentClass])) {
266 if ($converter !== NULL) {
274 if ($converter !== NULL) {
277 if (isset($convertersForSource[
'object'])) {
291 if (!is_array($converters)) {
296 foreach ($converters as $converter) {
297 if ($converter->canConvertFrom($source, $targetType)) {
311 $convertersForInterface = array();
312 foreach ($interfaceNames as $implementedInterface) {
313 if (isset($convertersForSource[$implementedInterface])) {
314 foreach ($convertersForSource[$implementedInterface] as $priority => $converter) {
315 if (isset($convertersForInterface[$priority])) {
316 throw new \TYPO3\CMS\Extbase\Property\Exception\DuplicateTypeConverterException(
'There exist at least two converters which handle the conversion to an interface with priority "' . $priority .
'". ' . get_class($convertersForInterface[$priority]) .
' and ' . get_class($converter), 1297951338);
318 $convertersForInterface[$priority] = $converter;
322 return $convertersForInterface;
333 if (is_string($source)) {
335 } elseif (is_array($source)) {
337 } elseif (is_float($source)) {
339 } elseif (is_integer($source)) {
341 } elseif (is_bool($source)) {
344 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidSourceException(
'The source is not of type string, array, float, integer or boolean, but of type "' . gettype($source) .
'"', 1297773150);
356 if (strpos($compositeType,
'<') !== FALSE) {
357 $compositeType = substr($compositeType, 0, strpos($compositeType,
'<'));
359 return $compositeType;
determineSourceType($source)
findEligibleConverterWithHighestPriority($converters, $source, $targetType)
doMapping($source, $targetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration, &$currentPropertyPath)
parseCompositeType($compositeType)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
findTypeConverter($source, $targetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getConvertersForInterfaces(array $convertersForSource, array $interfaceNames)
convert($source, $targetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration=NULL)