Example #1
0
 /**
  * Map everything to an array.
  *
  * @return array
  */
 public function toArray()
 {
     $array = [];
     if (!empty($this->data)) {
         $array['data'] = $this->data->toIdentifier();
     }
     if (!empty($this->meta)) {
         $array['meta'] = $this->meta;
     }
     if (!empty($this->links)) {
         $array['links'] = $this->links;
     }
     return $array;
 }
Example #2
0
 /**
  * Map everything to arrays.
  *
  * @return array
  */
 public function toArray()
 {
     $document = [];
     if (!empty($this->links)) {
         $document['links'] = $this->links;
     }
     if (!empty($this->data)) {
         $document['data'] = $this->data->toArray();
         $resources = $this->getIncluded($this->data);
         if (count($resources)) {
             $document['included'] = array_map(function (Resource $resource) {
                 return $resource->toArray();
             }, $resources);
         }
     }
     if (!empty($this->meta)) {
         $document['meta'] = $this->meta;
     }
     if (!empty($this->errors)) {
         $document['errors'] = $this->errors;
     }
     if (!empty($this->jsonapi)) {
         $document['jsonapi'] = $this->jsonapi;
     }
     return $document;
 }