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


PHP TypeHandling::truncateElementType方法代码示例

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


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

示例1: extractCollectionTypeReturnsOnlyTheMainType

 /**
  * @test
  * @dataProvider compositeTypes
  */
 public function extractCollectionTypeReturnsOnlyTheMainType($type, $expectedResult)
 {
     $this->assertEquals($expectedResult, TypeHandling::truncateElementType($type), 'Failed for ' . $type);
 }
开发者ID:mkeitsch,项目名称:flow-development-collection,代码行数:8,代码来源:TypeHandlingTest.php

示例2: findFirstEligibleTypeConverterInObjectHierarchy

 /**
  * Tries to find a suitable type converter for the given source and target type.
  *
  * @param string $source The actual source value
  * @param string $sourceType Type of the source to convert from
  * @param string $targetType Name of the target type to find a type converter for
  * @return mixed Either the matching object converter or NULL
  * @throws \TYPO3\Flow\Property\Exception\InvalidTargetException
  */
 protected function findFirstEligibleTypeConverterInObjectHierarchy($source, $sourceType, $targetType)
 {
     $targetClass = TypeHandling::truncateElementType($targetType);
     if (!class_exists($targetClass) && !interface_exists($targetClass)) {
         throw new \TYPO3\Flow\Property\Exception\InvalidTargetException(sprintf('Could not find a suitable type converter for "%s" because no such the class/interface "%s" does not exist.', $targetType, $targetClass), 1297948764);
     }
     if (!isset($this->typeConverters[$sourceType])) {
         return null;
     }
     $convertersForSource = $this->typeConverters[$sourceType];
     if (isset($convertersForSource[$targetClass])) {
         $converter = $this->findEligibleConverterWithHighestPriority($convertersForSource[$targetClass], $source, $targetType);
         if ($converter !== null) {
             return $converter;
         }
     }
     foreach (class_parents($targetClass) as $parentClass) {
         if (!isset($convertersForSource[$parentClass])) {
             continue;
         }
         $converter = $this->findEligibleConverterWithHighestPriority($convertersForSource[$parentClass], $source, $targetType);
         if ($converter !== null) {
             return $converter;
         }
     }
     $converters = $this->getConvertersForInterfaces($convertersForSource, class_implements($targetClass));
     $converter = $this->findEligibleConverterWithHighestPriority($converters, $source, $targetType);
     if ($converter !== null) {
         return $converter;
     }
     if (isset($convertersForSource['object'])) {
         return $this->findEligibleConverterWithHighestPriority($convertersForSource['object'], $source, $targetType);
     } else {
         return null;
     }
 }
开发者ID:patrickreck,项目名称:flow-development-collection,代码行数:45,代码来源:PropertyMapper.php

示例3: convertCallsCanConvertFromWithTheFullNormalizedTargetType

 /**
  * @test
  * @dataProvider convertCallsCanConvertFromWithTheFullNormalizedTargetTypeDataProvider
  */
 public function convertCallsCanConvertFromWithTheFullNormalizedTargetType($source, $fullTargetType)
 {
     $mockTypeConverter = $this->getMockTypeConverter();
     $mockTypeConverter->expects($this->atLeastOnce())->method('canConvertFrom')->with($source, $fullTargetType);
     $truncatedTargetType = TypeHandling::truncateElementType($fullTargetType);
     $mockTypeConverters = array(gettype($source) => array($truncatedTargetType => array(1 => $mockTypeConverter)));
     $propertyMapper = $this->getAccessibleMock('TYPO3\\Flow\\Property\\PropertyMapper', array('dummy'));
     $propertyMapper->_set('typeConverters', $mockTypeConverters);
     $mockConfiguration = $this->getMockBuilder('TYPO3\\Flow\\Property\\PropertyMappingConfiguration')->disableOriginalConstructor()->getMock();
     $propertyMapper->convert($source, $fullTargetType, $mockConfiguration);
     // dummy assertion to avoid PHPUnit warning
     $this->assertTrue(TRUE);
 }
开发者ID:sokunthearith,项目名称:Intern-Project-Week-2,代码行数:17,代码来源:PropertyMapperTest.php

示例4: 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::truncateElementType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。