95 if (isset($source[
'__type'])) {
96 unset($source[
'__type']);
113 $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\ObjectConverter::class, self::CONFIGURATION_TARGET_TYPE);
114 if ($configuredTargetType !==
null) {
115 return $configuredTargetType;
118 $specificTargetType = $this->objectContainer->getImplementationClassName(
$targetType);
119 $classSchema = $this->reflectionService->getClassSchema($specificTargetType);
121 if ($classSchema->hasMethod(\
TYPO3\CMS\
Extbase\Reflection\ObjectAccess::buildSetterMethodName($propertyName))) {
122 $methodParameters = $classSchema->getMethod(\
TYPO3\CMS\
Extbase\Reflection\ObjectAccess::buildSetterMethodName($propertyName))[
'params'] ?? [];
123 $methodParameter = current($methodParameters);
124 if (!isset($methodParameter[
'type'])) {
125 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException(
'Setter for property "' . $propertyName .
'" had no type hint or documentation in target object of type "' . $specificTargetType .
'".', 1303379158);
127 return $methodParameter[
'type'];
129 $method = $classSchema->getMethod(
'__construct');
130 if (empty($method)) {
131 $exceptionMessage = sprintf(
'Type of child property "%s" of class "%s" could not be '
132 .
'derived from constructor arguments as said class does not have a constructor '
133 .
'defined.', $propertyName, $specificTargetType);
134 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException($exceptionMessage, 1582385098);
137 $methodParameters = $classSchema->getMethod(
'__construct')[
'params'] ?? [];
138 if (!isset($methodParameters[$propertyName])) {
139 $exceptionMessage = sprintf(
'Type of child property "%1$s" of class "%2$s" could not be '
140 .
'derived from constructor arguments as the constructor of said class does not '
141 .
'have a parameter with property name "%1$s".', $propertyName, $specificTargetType);
142 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException($exceptionMessage, 1303379126);
145 $parameterType = $methodParameters[$propertyName][
'type'];
146 if ($parameterType ===
null) {
147 $exceptionMessage = sprintf(
'Type of child property "%1$s" of class "%2$s" could not be '
148 .
'derived from constructor argument "%1$s". This usually happens if the argument '
149 .
'misses a type hint.', $propertyName, $specificTargetType);
150 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException($exceptionMessage, 1582385619);
153 return $parameterType;
172 foreach ($convertedChildProperties as $propertyName => $propertyValue) {
174 if ($result ===
false) {
175 $exceptionMessage = sprintf(
176 'Property "%s" having a value of type "%s" could not be set in target object of type "%s". Make sure that the property is accessible properly, for example via an appropriate setter method.',
178 (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)),
181 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException($exceptionMessage, 1304538165);
204 if (is_array($source) && array_key_exists(
'__type', $source)) {
207 if ($configuration ===
null) {
208 throw new \InvalidArgumentException(
'A property mapping configuration must be given, not NULL.', 1326277369);
210 if ($configuration->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\ObjectConverter::class, self::CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED) !==
true) {
211 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidPropertyMappingConfigurationException(
'Override of target type not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED" to TRUE.', 1317050430);
215 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidDataTypeException(
'The given type "' .
$targetType .
'" is not a subtype of "' . $originalTargetType .
'".', 1317048056);
232 protected function buildObject(array &$possibleConstructorArgumentValues, $objectType)
234 $specificObjectType = $this->objectContainer->getImplementationClassName($objectType);
235 $classSchema = $this->reflectionService->getClassSchema($specificObjectType);
237 if ($classSchema->hasConstructor()) {
238 $constructorSignature = $classSchema->getMethod(
'__construct')[
'params'] ?? [];
239 $constructorArguments = [];
240 foreach ($constructorSignature as $constructorArgumentName => $constructorArgumentInformation) {
241 if (array_key_exists($constructorArgumentName, $possibleConstructorArgumentValues)) {
242 $constructorArguments[] = $possibleConstructorArgumentValues[$constructorArgumentName];
243 unset($possibleConstructorArgumentValues[$constructorArgumentName]);
244 } elseif ($constructorArgumentInformation[
'optional'] ===
true) {
245 $constructorArguments[] = $constructorArgumentInformation[
'defaultValue'];
247 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException(
'Missing constructor argument "' . $constructorArgumentName .
'" for object of type "' . $objectType .
'".', 1268734872);
250 return call_user_func_array([$this->objectManager,
'get'], array_merge([$objectType], $constructorArguments));
252 return $this->objectManager->get($objectType);