Esempio n. 1
0
 /**
  * Returns the given result as property value of the specified property type.
  *
  * @param DomainObjectInterface $parentObject
  * @param string $propertyName
  * @param mixed $result The result
  * @return mixed
  */
 public function mapResultToPropertyValue(DomainObjectInterface $parentObject, $propertyName, $result)
 {
     $propertyValue = null;
     if ($result instanceof Persistence\Generic\LoadingStrategyInterface) {
         $propertyValue = $result;
     } else {
         $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
         if (in_array($propertyMetaData['type'], ['array', 'ArrayObject', 'SplObjectStorage', \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class], true)) {
             $objects = [];
             foreach ($result as $value) {
                 $objects[] = $value;
             }
             if ($propertyMetaData['type'] === 'ArrayObject') {
                 $propertyValue = new \ArrayObject($objects);
             } elseif (in_array($propertyMetaData['type'], [\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class], true)) {
                 $propertyValue = new Persistence\ObjectStorage();
                 foreach ($objects as $object) {
                     $propertyValue->attach($object);
                 }
                 $propertyValue->_memorizeCleanState();
             } else {
                 $propertyValue = $objects;
             }
         } elseif (strpbrk($propertyMetaData['type'], '_\\') !== false) {
             if (is_object($result) && $result instanceof Persistence\QueryResultInterface) {
                 $propertyValue = $result->getFirst();
             } else {
                 $propertyValue = $result;
             }
         }
     }
     return $propertyValue;
 }