/** * @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; } } }