/** * @inheritdoc */ public function create(SerializerAbstract $serializer) { // Create a new Resource bag for transforming relationships. $resourceBag = new ResourceBag($this->data, $this->transformer, $serializer); // Transform raw data into correct format/s $transformed = $this->transformer->transform($this->data); // Convert into final resource object $resource = $serializer->item($transformed, $this->transformer); // Pull relationships into the correct format $relationships = $serializer->relationships($resourceBag, $this->transformer); return array_merge($resource, $relationships); }
/** * Returns an array of sideloadable relationships. * * @return array */ public function fetchSideloads() { $resources = array(); foreach ($this->transformer->getIncludedResources() as $key => $resource) { if ($resource instanceof ResourceAbstract) { $data = $resource->identifiers($this->serializer); $resources[$key] = $this->serializer->sideload($data, $resource->getTransformer()->getTypeKey()); } } return $resources; }
/** * Translate a item into a resource and serialize the payload. * * @param ResourceAbstract $resource * @param string $resourceKey * @return array */ public function translate(ResourceAbstract $resource, $resourceKey = null) { $resource = $resource->create($this->serializer); return $this->serializer->payload($resource, $resourceKey); }