2 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
90 return !is_subclass_of(
$targetType, \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject::class);
101 if (isset($source[
'__type'])) {
102 unset($source[
'__type']);
118 $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue(\TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter::class, self::CONFIGURATION_TARGET_TYPE);
119 if ($configuredTargetType !== null) {
120 return $configuredTargetType;
123 $specificTargetType = $this->objectContainer->getImplementationClassName(
$targetType);
124 if ($this->reflectionService->hasMethod($specificTargetType, \TYPO3\CMS\Extbase\Reflection\ObjectAccess::buildSetterMethodName($propertyName))) {
125 $methodParameters = $this->reflectionService->getMethodParameters($specificTargetType, \TYPO3\CMS\Extbase\Reflection\ObjectAccess::buildSetterMethodName($propertyName));
126 $methodParameter = current($methodParameters);
127 if (!isset($methodParameter[
'type'])) {
128 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);
130 return $methodParameter[
'type'];
133 $methodParameters = $this->reflectionService->getMethodParameters($specificTargetType,
'__construct');
134 if (isset($methodParameters[$propertyName]) && isset($methodParameters[$propertyName][
'type'])) {
135 return $methodParameters[$propertyName][
'type'];
137 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException(
'Property "' . $propertyName .
'" had no setter or constructor argument in target object of type "' . $specificTargetType .
'".', 1303379126);
157 foreach ($convertedChildProperties as $propertyName => $propertyValue) {
158 $result = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($object, $propertyName, $propertyValue);
159 if ($result ===
false) {
160 $exceptionMessage = sprintf(
161 '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.',
163 (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)),
166 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException($exceptionMessage, 1304538165);
188 if (is_array($source) && array_key_exists(
'__type', $source)) {
191 if ($configuration === null) {
192 throw new \InvalidArgumentException(
'A property mapping configuration must be given, not NULL.', 1326277369);
194 if ($configuration->getConfigurationValue(\TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter::class, self::CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED) !==
true) {
195 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);
199 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidDataTypeException(
'The given type "' .
$targetType .
'" is not a subtype of "' . $originalTargetType .
'".', 1317048056);
216 protected function buildObject(array &$possibleConstructorArgumentValues, $objectType)
218 $specificObjectType = $this->objectContainer->getImplementationClassName($objectType);
219 if ($this->reflectionService->hasMethod($specificObjectType,
'__construct')) {
220 $constructorSignature = $this->reflectionService->getMethodParameters($specificObjectType,
'__construct');
221 $constructorArguments = array();
222 foreach ($constructorSignature as $constructorArgumentName => $constructorArgumentInformation) {
223 if (array_key_exists($constructorArgumentName, $possibleConstructorArgumentValues)) {
224 $constructorArguments[] = $possibleConstructorArgumentValues[$constructorArgumentName];
225 unset($possibleConstructorArgumentValues[$constructorArgumentName]);
226 }
elseif ($constructorArgumentInformation[
'optional'] ===
true) {
227 $constructorArguments[] = $constructorArgumentInformation[
'defaultValue'];
229 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException(
'Missing constructor argument "' . $constructorArgumentName .
'" for object of type "' . $objectType .
'".', 1268734872);
232 return call_user_func_array(array($this->objectManager,
'get'), array_merge(array($objectType), $constructorArguments));
234 return $this->objectManager->get($objectType);