Example #1
0
 /**
  * Serialize a resource.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param  \League\Fractal\Serializer\SerializerAbstract $serializer
  * @param  mixed                                         $data
  * @return array
  */
 protected function serializeResource(FractalSerializerAbstract $serializer, $data)
 {
     $resourceKey = $this->resource->getResourceKey();
     if ($this->resource instanceof FractalCollection) {
         return $serializer->collection($resourceKey, $data);
     } elseif ($this->resource instanceof FractalItem) {
         return $serializer->item($resourceKey, $data);
     } elseif ($this->resource instanceof NodesResourceContent) {
         return !empty($resourceKey) ? [$resourceKey => $data] : $data;
     }
     return $serializer->null();
 }
Example #2
0
 /**
  * Serialize a resource
  *
  * @internal
  *
  * @param SerializerAbstract $serializer
  * @param mixed              $data
  *
  * @return array
  */
 protected function serializeResource(SerializerAbstract $serializer, $data)
 {
     $resourceKey = $this->resource->getResourceKey();
     if ($this->resource instanceof Collection) {
         return $serializer->collection($resourceKey, $data);
     }
     if ($this->resource instanceof Item) {
         return $serializer->item($resourceKey, $data);
     }
     return $serializer->null();
 }