/** * @param ResourceContract $resource * @param $resourceDefinition * @param EntityFactoryContract $factory * @param mixed|null $entity * @param ContextContract $context * @return mixed $entity */ public function toEntity(ResourceContract $resource, $resourceDefinition, EntityFactoryContract $factory, Context $context, $entity = null) { $resourceDefinition = ResourceDefinitionLibrary::make($resourceDefinition); if ($entity === null) { $entity = $factory->createEntity($resourceDefinition->getEntityClassName(), $context); } $this->parents->push($entity); $values = $resource->getProperties()->getValues(); foreach ($values as $property) { $property->toEntity($entity, $this, $this->propertyResolver, $this->propertySetter, $factory, $context); } $this->parents->pop(); return $entity; }
/** * @param PaginationBuilder $builder * @param RESTResource $resource * @return mixed */ private function transformResource(PaginationBuilder $builder, RESTResource $resource) { $sortOrder = $builder->getOrderBy(); $properties = $resource->getProperties(); $out = []; foreach ($sortOrder as $sort) { $value = $properties->getFromName($sort->getColumn()); if ($value) { $out[$value->getField()->getName()] = $value->getValue(); } } // Also add identifiers foreach ($resource->getProperties()->getIdentifiers()->getValues() as $identifier) { if (!isset($out[$identifier->getField()->getName()])) { $out[$identifier->getField()->getName()] = $identifier->getValue(); } } return $out; }