当前位置: 首页>>代码示例>>PHP>>正文


PHP TypeHandling::normalizeType方法代码示例

本文整理汇总了PHP中TYPO3\Flow\Utility\TypeHandling::normalizeType方法的典型用法代码示例。如果您正苦于以下问题:PHP TypeHandling::normalizeType方法的具体用法?PHP TypeHandling::normalizeType怎么用?PHP TypeHandling::normalizeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TYPO3\Flow\Utility\TypeHandling的用法示例。


在下文中一共展示了TypeHandling::normalizeType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: expandType

 /**
  * Expand shortened class names in "var" and "param" annotations, taking use statements into account.
  *
  * @param ClassReflection $class
  * @param string $type the type inside var/param annotation
  * @return string the possibly expanded type
  */
 protected function expandType(ClassReflection $class, $type)
 {
     // expand "SomeType<SomeElementType>" to "\SomeTypeNamespace\SomeType<\ElementTypeNamespace\ElementType>"
     if (strpos($type, '<') !== false) {
         $typeParts = explode('<', $type);
         $type = $typeParts[0];
         $elementType = rtrim($typeParts[1], '>');
         return $this->expandType($class, $type) . '<' . $this->expandType($class, $elementType) . '>';
     }
     // skip simple types and types with fully qualified namespaces
     if ($type === 'mixed' || $type[0] === '\\' || TypeHandling::isSimpleType($type)) {
         return TypeHandling::normalizeType($type);
     }
     // we try to find the class relative to the current namespace...
     $possibleFullyQualifiedClassName = sprintf('%s\\%s', $class->getNamespaceName(), $type);
     if (class_exists($possibleFullyQualifiedClassName) || interface_exists($possibleFullyQualifiedClassName)) {
         return $possibleFullyQualifiedClassName;
     }
     // and then we try to find "use" statements for the class.
     $className = $class->getName();
     if (!isset($this->useStatementsForClassCache[$className])) {
         $this->useStatementsForClassCache[$className] = $this->getDoctrinePhpParser()->parseClass($class);
     }
     $useStatementsForClass = $this->useStatementsForClassCache[$className];
     // ... and try to expand them
     $typeParts = explode('\\', $type, 2);
     $lowercasedFirstTypePart = strtolower($typeParts[0]);
     if (isset($useStatementsForClass[$lowercasedFirstTypePart])) {
         $typeParts[0] = $useStatementsForClass[$lowercasedFirstTypePart];
         return implode('\\', $typeParts);
     }
     return $type;
 }
开发者ID:mkeitsch,项目名称:flow-development-collection,代码行数:40,代码来源:ReflectionService.php

示例2: normalizeTypesReturnsNormalizedType

 /**
  * @test
  * @dataProvider normalizeTypes
  */
 public function normalizeTypesReturnsNormalizedType($type, $normalized)
 {
     $this->assertEquals(TypeHandling::normalizeType($type), $normalized);
 }
开发者ID:mkeitsch,项目名称:flow-development-collection,代码行数:8,代码来源:TypeHandlingTest.php

示例3: setDataType

 /**
  * Sets the data type of this argument that is also used for property mapping.
  * @param string $dataType
  * @return \TYPO3\Flow\Mvc\Controller\Argument $this
  */
 public function setDataType($dataType)
 {
     $this->dataType = \TYPO3\Flow\Utility\TypeHandling::normalizeType($dataType);
     return $this;
 }
开发者ID:robertlemke,项目名称:flow-development-collection,代码行数:10,代码来源:Argument.php

示例4: handleSimpleTypeOperand

 /**
  * @param string $operand
  * @param string $value
  * @return boolean TRUE if $value is of type $operand; FALSE otherwise
  */
 protected function handleSimpleTypeOperand($operand, $value)
 {
     $operand = \TYPO3\Flow\Utility\TypeHandling::normalizeType($operand);
     if ($operand === 'object') {
         return is_object($value);
     } elseif ($operand === 'string') {
         return is_string($value);
     } elseif ($operand === 'integer') {
         return is_integer($value);
     } elseif ($operand === 'boolean') {
         return is_bool($value);
     } elseif ($operand === 'float') {
         return is_float($value);
     } elseif ($operand === 'array') {
         return is_array($value);
     }
     return false;
 }
开发者ID:Weissheiten,项目名称:flow-development-collection,代码行数:23,代码来源:FilterOperation.php

示例5: findTypeConverter

 /**
  * Determine the type converter to be used. If no converter has been found, an exception is raised.
  *
  * @param mixed $source
  * @param string $targetType
  * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration
  * @return \TYPO3\Flow\Property\TypeConverterInterface Type Converter which should be used to convert between $source and $targetType.
  * @throws \TYPO3\Flow\Property\Exception\TypeConverterException
  * @throws \TYPO3\Flow\Property\Exception\InvalidTargetException
  */
 protected function findTypeConverter($source, $targetType, \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration)
 {
     if ($configuration->getTypeConverter() !== null) {
         return $configuration->getTypeConverter();
     }
     if (!is_string($targetType)) {
         throw new \TYPO3\Flow\Property\Exception\InvalidTargetException('The target type was no string, but of type "' . gettype($targetType) . '"', 1297941727);
     }
     $normalizedTargetType = TypeHandling::normalizeType($targetType);
     $truncatedTargetType = TypeHandling::truncateElementType($normalizedTargetType);
     $converter = null;
     $sourceTypes = $this->determineSourceTypes($source);
     foreach ($sourceTypes as $sourceType) {
         if (TypeHandling::isSimpleType($truncatedTargetType)) {
             if (isset($this->typeConverters[$sourceType][$truncatedTargetType])) {
                 $converter = $this->findEligibleConverterWithHighestPriority($this->typeConverters[$sourceType][$truncatedTargetType], $source, $normalizedTargetType);
             }
         } else {
             $converter = $this->findFirstEligibleTypeConverterInObjectHierarchy($source, $sourceType, $normalizedTargetType);
         }
         if ($converter !== null) {
             return $converter;
         }
     }
     throw new \TYPO3\Flow\Property\Exception\TypeConverterException('No converter found which can be used to convert from "' . implode('" or "', $sourceTypes) . '" to "' . $normalizedTargetType . '".');
 }
开发者ID:patrickreck,项目名称:flow-development-collection,代码行数:36,代码来源:PropertyMapper.php

示例6: setDataType

 /**
  * Sets the data type of this argument that is also used for property mapping.
  * @param string $dataType
  * @return Argument $this
  * @deprecated Will be removed for next major Flow version. Set the DataType via constructor.
  */
 public function setDataType($dataType)
 {
     $this->dataType = TypeHandling::normalizeType($dataType);
     return $this;
 }
开发者ID:mkeitsch,项目名称:flow-development-collection,代码行数:11,代码来源:Argument.php

示例7: convertValue

 /**
  * @param mixed $propertyValue
  * @param string $dataType
  * @return mixed
  * @throws PropertyException
  */
 protected function convertValue($propertyValue, $dataType)
 {
     $rawType = TypeHandling::truncateElementType($dataType);
     // This hardcoded handling is to circumvent rewriting PropertyMappers that convert objects. Usually they expect the source to be an object already and break if not.
     if (!TypeHandling::isSimpleType($rawType) && !is_object($propertyValue) && !is_array($propertyValue)) {
         return null;
     }
     if ($rawType === 'array') {
         $conversionTargetType = 'array<string>';
     } elseif (TypeHandling::isSimpleType($rawType)) {
         $conversionTargetType = TypeHandling::normalizeType($rawType);
     } else {
         $conversionTargetType = 'array';
     }
     $propertyMappingConfiguration = $this->createConfiguration($dataType);
     $convertedValue = $this->propertyMapper->convert($propertyValue, $conversionTargetType, $propertyMappingConfiguration);
     if ($convertedValue instanceof \TYPO3\Flow\Error\Error) {
         throw new PropertyException($convertedValue->getMessage(), $convertedValue->getCode());
     }
     return $convertedValue;
 }
开发者ID:robertlemke,项目名称:neos-development-collection,代码行数:27,代码来源:NodePropertyConverterService.php


注:本文中的TYPO3\Flow\Utility\TypeHandling::normalizeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。