/**
  * Convert the current data for this scope to an array.
  *
  * @return array
  */
 public function toArray()
 {
     list($rawData, $rawIncludedData) = $this->executeResourceTransformers();
     $serializer = $this->manager->getSerializer();
     $data = $this->serializeResource($serializer, $rawData);
     // If the serializer wants the includes to be side-loaded then we'll
     // serialize the included data and merge it with the data.
     if ($serializer->sideloadIncludes()) {
         $includedData = $serializer->includedData($this->resource, $rawIncludedData);
         // If the serializer wants to inject additional information
         // about the included resources, it can do so now.
         $data = $serializer->injectData($data, $rawIncludedData);
         if ($this->isRootScope()) {
             // If the serializer wants to have a final word about all
             // the objects that are sideloaded, it can do so now.
             $includedData = $serializer->filterIncludes($includedData, $data);
         }
         $data = array_merge($data, $includedData);
     }
     if ($this->resource instanceof Collection) {
         if ($this->resource->hasCursor()) {
             $pagination = $serializer->cursor($this->resource->getCursor());
         } elseif ($this->resource->hasPaginator()) {
             $pagination = $serializer->paginator($this->resource->getPaginator());
         }
         if (!empty($pagination)) {
             $this->resource->setMetaValue(key($pagination), current($pagination));
         }
     }
     // Pull out all of OUR metadata and any custom meta data to merge with the main level data
     $meta = $serializer->meta($this->resource->getMeta());
     return array_merge($data, $meta);
 }
Exemple #2
0
 /**
  * Convert the current data for this scope to an array.
  *
  * @return array
  */
 public function toArray()
 {
     list($rawData, $rawIncludedData) = $this->executeResourceTransformers();
     $serializer = $this->manager->getSerializer();
     $data = $this->serializeResource($serializer, $rawData);
     // If the serializer wants the includes to be side-loaded then we'll
     // serialize the included data and merge it with the data.
     if ($serializer->sideloadIncludes()) {
         $includedData = $serializer->includedData($this->resource, $rawIncludedData);
         $data = array_merge($data, $includedData);
     }
     if ($this->resource instanceof Collection) {
         if ($this->resource->hasCursor()) {
             $pagination = $serializer->cursor($this->resource->getCursor());
         } elseif ($this->resource->hasPaginator()) {
             $pagination = $serializer->paginator($this->resource->getPaginator());
         }
         if (!empty($pagination)) {
             $this->resource->setMetaValue(key($pagination), current($pagination));
         }
     }
     // Pull out all of OUR metadata and any custom meta data to merge with the main level data
     $meta = $serializer->meta($this->resource->getMeta());
     return array_merge($data, $meta);
 }