Exemplo n.º 1
0
 /**
  * Determine the type converter to be used. If no converter has been found, an exception is raised.
  *
  * @param mixed $source
  * @param string $targetType
  * @param PropertyMappingConfigurationInterface $configuration
  * @throws Exception\TypeConverterException
  * @throws Exception\InvalidTargetException
  * @return \TYPO3\CMS\Extbase\Property\TypeConverterInterface Type Converter which should be used to convert between $source and $targetType.
  */
 protected function findTypeConverter($source, $targetType, PropertyMappingConfigurationInterface $configuration)
 {
     if ($configuration->getTypeConverter() !== null) {
         return $configuration->getTypeConverter();
     }
     $sourceType = $this->determineSourceType($source);
     if (!is_string($targetType)) {
         throw new Exception\InvalidTargetException('The target type was no string, but of type "' . gettype($targetType) . '"', 1297941727);
     }
     $targetType = $this->parseCompositeType($targetType);
     // This is needed to correctly convert old class names to new ones
     // This compatibility layer will be removed with 7.0
     $targetType = \TYPO3\CMS\Core\Core\ClassLoadingInformation::getClassNameForAlias($targetType);
     $targetType = TypeHandlingUtility::normalizeType($targetType);
     $converter = null;
     if (TypeHandlingUtility::isSimpleType($targetType)) {
         if (isset($this->typeConverters[$sourceType][$targetType])) {
             $converter = $this->findEligibleConverterWithHighestPriority($this->typeConverters[$sourceType][$targetType], $source, $targetType);
         }
     } else {
         $converter = $this->findFirstEligibleTypeConverterInObjectHierarchy($source, $sourceType, $targetType);
     }
     if ($converter === null) {
         throw new Exception\TypeConverterException('No converter found which can be used to convert from "' . $sourceType . '" to "' . $targetType . '".');
     }
     return $converter;
 }
Exemplo n.º 2
0
 /**
  * Constructs this controller argument
  *
  * @param string $name Name of this argument
  * @param string $dataType The data type of this argument
  * @throws \InvalidArgumentException if $name is not a string or empty
  * @api
  */
 public function __construct($name, $dataType)
 {
     if (!is_string($name)) {
         throw new \InvalidArgumentException('$name must be of type string, ' . gettype($name) . ' given.', 1187951688);
     }
     if (strlen($name) === 0) {
         throw new \InvalidArgumentException('$name must be a non-empty string, ' . strlen($name) . ' characters given.', 1232551853);
     }
     $this->name = $name;
     $this->dataType = TypeHandlingUtility::normalizeType($dataType);
 }
Exemplo n.º 3
0
 /**
  * Normalize data types so they match the PHP type names:
  * int -> integer
  * float -> double
  * bool -> boolean
  *
  * @param string $type Data type to unify
  * @return string unified data type
  */
 public function normalizeType($type)
 {
     return TypeHandlingUtility::normalizeType($type);
 }