Example #1
0
 /**
  * Convert a value to the internal object data format
  *
  * @param string $identifier The object's identifier
  * @param object $object The object with the property to flatten
  * @param string $propertyName The name of the property
  * @param array $propertyMetaData The property metadata
  * @param array $propertyData Reference to the property data array
  * @return void
  * @api
  */
 protected function flattenValue($identifier, $object, $propertyName, array $propertyMetaData, array &$propertyData)
 {
     $propertyValue = \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($object, $propertyName, TRUE);
     if ($propertyValue instanceof \TYPO3\FLOW3\Persistence\Aspect\PersistenceMagicInterface) {
         $propertyData[$propertyName] = array('type' => get_class($propertyValue), 'multivalue' => FALSE, 'value' => $this->processObject($propertyValue, $identifier));
     } else {
         switch ($propertyMetaData['type']) {
             case 'DateTime':
                 $propertyData[$propertyName] = array('multivalue' => FALSE, 'value' => $this->processDateTime($propertyValue));
                 break;
             case 'Doctrine\\Common\\Collections\\Collection':
             case 'Doctrine\\Common\\Collections\\ArrayCollection':
                 $propertyValue = $propertyValue === NULL ? array() : $propertyValue->toArray();
             case 'array':
                 $propertyData[$propertyName] = array('multivalue' => TRUE, 'value' => $this->processArray($propertyValue, $identifier, $this->persistenceSession->getCleanStateOfProperty($object, $propertyName)));
                 break;
             case 'SplObjectStorage':
                 $propertyData[$propertyName] = array('multivalue' => TRUE, 'value' => $this->processSplObjectStorage($propertyValue, $identifier, $this->persistenceSession->getCleanStateOfProperty($object, $propertyName)));
                 break;
             default:
                 if ($propertyValue === NULL && !\TYPO3\FLOW3\Utility\TypeHandling::isSimpleType($propertyMetaData['type'])) {
                     $this->removeDeletedReference($object, $propertyName, $propertyMetaData);
                 }
                 $propertyData[$propertyName] = array('multivalue' => FALSE, 'value' => $propertyValue);
                 break;
         }
         $propertyData[$propertyName]['type'] = $propertyMetaData['type'];
     }
 }
Example #2
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 \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration
  * @return \TYPO3\FLOW3\Property\TypeConverterInterface Type Converter which should be used to convert between $source and $targetType.
  * @throws \TYPO3\FLOW3\Property\Exception\TypeConverterException
  * @throws \TYPO3\FLOW3\Property\Exception\InvalidTargetException
  */
 protected function findTypeConverter($source, $targetType, \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration)
 {
     if ($configuration->getTypeConverter() !== NULL) {
         return $configuration->getTypeConverter();
     }
     $sourceType = $this->determineSourceType($source);
     if (!is_string($targetType)) {
         throw new \TYPO3\FLOW3\Property\Exception\InvalidTargetException('The target type was no string, but of type "' . gettype($targetType) . '"', 1297941727);
     }
     if (strpos($targetType, '<') !== FALSE) {
         $targetType = substr($targetType, 0, strpos($targetType, '<'));
     }
     $converter = NULL;
     if (\TYPO3\FLOW3\Utility\TypeHandling::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 \TYPO3\FLOW3\Property\Exception\TypeConverterException('No converter found which can be used to convert from "' . $sourceType . '" to "' . $targetType . '".');
     }
     return $converter;
 }