/**
* 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;
}