Ojs\CoreBundle\Service\ApiHandlerHelper::normalizeEntity PHP Метод

normalizeEntity() публичный Метод

public normalizeEntity ( $entity )
$entity
    public function normalizeEntity($entity)
    {
        if (is_object($entity)) {
            $reflectionClass = new \ReflectionClass($entity);
            foreach ($reflectionClass->getProperties() as $property) {
                foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
                    $getSetter = 'set' . ucfirst($property->name);
                    $getGetter = 'get' . ucfirst($property->name);
                    if (method_exists($entity, $getGetter) && !empty($entity->{$getGetter}())) {
                        if (method_exists($entity->{$getGetter}(), 'first')) {
                            foreach ($entity->{$getGetter}() as $object) {
                                $this->normalizeEntity($object);
                            }
                        }
                        if ($annotation instanceof File) {
                            if (!preg_match('/http/', $entity->{$getGetter}())) {
                                $fileFullPath = $this->requestStack->getCurrentRequest()->getSchemeAndHttpHost() . '/uploads/' . $annotation->getPath() . '/' . $entity->{$getGetter}();
                                $entity->{$getSetter}($fileFullPath);
                            }
                        } elseif ($annotation instanceof Image) {
                            if (!preg_match('/http/', $entity->{$getGetter}())) {
                                $filteredImage = $this->imagine->filter($entity->{$getGetter}(), $annotation->getFilter());
                                $entity->{$getSetter}($filteredImage);
                            }
                        }
                    }
                }
            }
        }
        return $entity;
    }