Пример #1
0
 /**
  * @param $model
  * @return \stdClass
  */
 public function transform($model)
 {
     if ($model instanceof \Traversable) {
         $out = array();
         foreach ($model as $subModel) {
             $out[] = $this->transform($subModel);
         }
         return $out;
     } else {
         if ($model instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
             $transformedObject = new \stdClass();
             $properties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettablePropertyNames($model);
             $class = get_class($model);
             foreach ($properties as $property) {
                 $getMethodName = 'get' . ucfirst($property);
                 $methodTags = $this->reflectionService->getMethodTagsValues($class, $getMethodName);
                 // The Goal here is to be able to expose properties and methods with the JSONExpose annotation.
                 if ($property == 'uid' || array_key_exists('JSONExpose', $methodTags) || $this->reflectionService->isPropertyTaggedWith($class, $property, 'JSONExpose')) {
                     $value = $model->{$getMethodName}();
                     // TODO, not sure about this check for lazy loading. Would be good to write a test for it.
                     if ($value instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
                         $transformedObject->{$property} = 'lazy';
                     } elseif ($this->typeHandlingService->isSimpleType(gettype($value))) {
                         $transformedObject->{$property} = $value;
                     } elseif (is_object($value)) {
                         if ($value instanceof \TYPO3\CMS\Extbase\Persistence\ObjectStorage) {
                             $transformedObject->{$property} = $this->transform($value);
                         } else {
                             $transformedObject->{$property} = get_class($value);
                         }
                     }
                 }
             }
             return $transformedObject;
         } else {
             return NULL;
         }
     }
 }
 /**
  * @param \TYPO3\CMS\Extbase\Service\TypeHandlingService $typeHandlingService
  * @return void
  */
 public function injectTypeHandlingService(\TYPO3\CMS\Extbase\Service\TypeHandlingService $typeHandlingService)
 {
     $this->typeHandlingService = $typeHandlingService;
     $this->dataType = $this->typeHandlingService->normalizeType($this->dataType);
 }
Пример #3
0
 /**
  * Adds (defines) a specific property and its type.
  *
  * @param string $name Name of the property
  * @param string $type Type of the property
  * @param boolean $lazy Whether the property should be lazy-loaded when reconstituting
  * @param string $cascade Strategy to cascade the object graph.
  * @return void
  */
 public function addProperty($name, $type, $lazy = FALSE, $cascade = '')
 {
     $type = $this->typeHandlingService->parseType($type);
     $this->properties[$name] = array('type' => $type['type'], 'elementType' => $type['elementType'], 'lazy' => $lazy, 'cascade' => $cascade);
 }
 /**
  * @test
  * @dataProvider simpleTypes
  * @author Alexander Schnitzler <*****@*****.**>
  * @param string $type
  * @param boolean $result
  */
 public function isSimpleTypeReturnsOnlyTrueForSimpleTypes($type, $result)
 {
     $this->assertSame($result, $this->typeHandlingService->isSimpleType($type));
 }