/** * The type of a property is determined by the reflection service. * * @param string $targetType * @param string $propertyName * @param PropertyMappingConfigurationInterface $configuration * @return string * @throws InvalidTargetException */ public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappingConfigurationInterface $configuration) { $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', self::CONFIGURATION_TARGET_TYPE); if ($configuredTargetType !== NULL) { return $configuredTargetType; } $schema = $this->reflectionService->getClassSchema($targetType); $setterMethodName = ObjectAccess::buildSetterMethodName($propertyName); if ($schema->hasProperty($propertyName)) { $propertyInformation = $schema->getProperty($propertyName); return $propertyInformation['type'] . ($propertyInformation['elementType'] !== NULL ? '<' . $propertyInformation['elementType'] . '>' : ''); } elseif ($this->reflectionService->hasMethod($targetType, $setterMethodName)) { $methodParameters = $this->reflectionService->getMethodParameters($targetType, $setterMethodName); $methodParameter = current($methodParameters); if (!isset($methodParameter['type'])) { throw new InvalidTargetException('Setter for property "' . $propertyName . '" had no type hint or documentation in target object of type "' . $targetType . '".', 1303379158); } else { return $methodParameter['type']; } } else { throw new InvalidTargetException('Property "' . $propertyName . '" was not found in target object of type "' . $targetType . '".', 1297978366); } }
/** * The type of a property is determined by the reflection service. * * @param string $targetType * @param string $propertyName * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration * @return string * @throws \TYPO3\Flow\Property\Exception\InvalidTargetException */ public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration) { $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', self::CONFIGURATION_TARGET_TYPE); if ($configuredTargetType !== NULL) { return $configuredTargetType; } $varAnnotations = $this->reflectionService->getPropertyTagValues($targetType, $propertyName, 'var'); if ($varAnnotations === array()) { // No @var annotation found for property, use string as default // TODO: Read this from some kind of configuration return 'string'; } $propertyInformation = \TYPO3\Flow\Utility\TypeHandling::parseType($varAnnotations[0]); return $propertyInformation['type'] . ($propertyInformation['elementType'] !== NULL ? '<' . $propertyInformation['elementType'] . '>' : ''); }
/** * The type of a property is determined by the reflection service. * * @param string $targetType * @param string $propertyName * @param PropertyMappingConfigurationInterface $configuration * @return string * @throws InvalidTargetException */ public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappingConfigurationInterface $configuration) { $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue(ObjectConverter::class, self::CONFIGURATION_TARGET_TYPE); if ($configuredTargetType !== null) { return $configuredTargetType; } $methodParameters = $this->reflectionService->getMethodParameters($targetType, '__construct'); if (isset($methodParameters[$propertyName]) && isset($methodParameters[$propertyName]['type'])) { return $methodParameters[$propertyName]['type']; } elseif ($this->reflectionService->hasMethod($targetType, ObjectAccess::buildSetterMethodName($propertyName))) { $methodParameters = $this->reflectionService->getMethodParameters($targetType, ObjectAccess::buildSetterMethodName($propertyName)); $methodParameter = current($methodParameters); if (!isset($methodParameter['type'])) { throw new InvalidTargetException('Setter for property "' . $propertyName . '" had no type hint or documentation in target object of type "' . $targetType . '".', 1303379158); } else { return $methodParameter['type']; } } else { $targetPropertyNames = $this->reflectionService->getClassPropertyNames($targetType); if (in_array($propertyName, $targetPropertyNames)) { $varTagValues = $this->reflectionService->getPropertyTagValues($targetType, $propertyName, 'var'); if (count($varTagValues) > 0) { // This ensures that FQCNs are returned without leading backslashes. Otherwise, something like @var \DateTime // would not find a property mapper. It is needed because the ObjectConverter doesn't use class schemata, // but reads the annotations directly. $declaredType = strtok(trim(current($varTagValues), " \n\t"), " \n\t"); try { $parsedType = TypeHandling::parseType($declaredType); } catch (InvalidTypeException $exception) { throw new \InvalidArgumentException(sprintf($exception->getMessage(), 'class "' . $targetType . '" for property "' . $propertyName . '"'), 1467699674); } return $parsedType['type'] . ($parsedType['elementType'] !== null ? '<' . $parsedType['elementType'] . '>' : ''); } else { throw new InvalidTargetException(sprintf('Public property "%s" had no proper type annotation (i.e. "@var") in target object of type "%s".', $propertyName, $targetType), 1406821818); } } } throw new InvalidTargetException(sprintf('Property "%s" has neither a setter or constructor argument, nor is public, in target object of type "%s".', $propertyName, $targetType), 1303379126); }
/** * The type of a property is determined by the reflection service. * * @param string $targetType * @param string $propertyName * @param PropertyMappingConfigurationInterface $configuration * @return string * @throws InvalidTargetException */ public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappingConfigurationInterface $configuration) { $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue(\TYPO3\Flow\Property\TypeConverter\ObjectConverter::class, self::CONFIGURATION_TARGET_TYPE); if ($configuredTargetType !== NULL) { return $configuredTargetType; } $methodParameters = $this->reflectionService->getMethodParameters($targetType, '__construct'); if (isset($methodParameters[$propertyName]) && isset($methodParameters[$propertyName]['type'])) { return $methodParameters[$propertyName]['type']; } elseif ($this->reflectionService->hasMethod($targetType, ObjectAccess::buildSetterMethodName($propertyName))) { $methodParameters = $this->reflectionService->getMethodParameters($targetType, ObjectAccess::buildSetterMethodName($propertyName)); $methodParameter = current($methodParameters); if (!isset($methodParameter['type'])) { throw new InvalidTargetException('Setter for property "' . $propertyName . '" had no type hint or documentation in target object of type "' . $targetType . '".', 1303379158); } else { return $methodParameter['type']; } } else { $targetPropertyNames = $this->reflectionService->getClassPropertyNames($targetType); if (in_array($propertyName, $targetPropertyNames)) { $values = $this->reflectionService->getPropertyTagValues($targetType, $propertyName, 'var'); if (count($values) > 0) { return current($values); } else { throw new InvalidTargetException(sprintf('Public property "%s" had no proper type annotation (i.e. "@var") in target object of type "%s".', $propertyName, $targetType), 1406821818); } } } throw new InvalidTargetException(sprintf('Property "%s" has neither a setter or constructor argument, nor is public, in target object of type "%s".', $propertyName, $targetType), 1303379126); }
/** * The type of a property is determined by the reflection service. * * @param string $targetType * @param string $propertyName * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration * @return string * @throws \TYPO3\Flow\Property\Exception\InvalidTargetException */ public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration) { $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue('TYPO3\\Flow\\Property\\TypeConverter\\ObjectConverter', self::CONFIGURATION_TARGET_TYPE); if ($configuredTargetType !== NULL) { return $configuredTargetType; } if ($this->reflectionService->hasMethod($targetType, \TYPO3\Flow\Reflection\ObjectAccess::buildSetterMethodName($propertyName))) { $methodParameters = $this->reflectionService->getMethodParameters($targetType, \TYPO3\Flow\Reflection\ObjectAccess::buildSetterMethodName($propertyName)); $methodParameter = current($methodParameters); if (!isset($methodParameter['type'])) { throw new \TYPO3\Flow\Property\Exception\InvalidTargetException('Setter for property "' . $propertyName . '" had no type hint or documentation in target object of type "' . $targetType . '".', 1303379158); } else { return $methodParameter['type']; } } else { $methodParameters = $this->reflectionService->getMethodParameters($targetType, '__construct'); if (isset($methodParameters[$propertyName]) && isset($methodParameters[$propertyName]['type'])) { return $methodParameters[$propertyName]['type']; } else { throw new \TYPO3\Flow\Property\Exception\InvalidTargetException('Property "' . $propertyName . '" had no setter or constructor argument in target object of type "' . $targetType . '".', 1303379126); } } }