SuiteCRM-Core/Api/V8/JsonApi/Response/DocumentResponse.php
Dillon-Brown 8e4cc94994 Squashed 'public/legacy/' content from commit 817a12dc0
git-subtree-dir: public/legacy
git-subtree-split: 817a12dc0c30c189f56d5cb1f7dc37a9631bdbe3
2021-03-31 15:37:32 +01:00

92 lines
1.6 KiB
PHP

<?php
namespace Api\V8\JsonApi\Response;
class DocumentResponse implements \JsonSerializable
{
/**
* @var array|DataResponse|DataResponse[]
*/
private $data = [];
/**
* @var MetaResponse
*/
private $meta;
/**
* @var LinksResponse
*/
private $links;
/**
* @return array|DataResponse|DataResponse[]
*/
public function getData()
{
return $this->data;
}
/**
* @param array|DataResponse|DataResponse[] $data
*/
public function setData($data)
{
$this->data = $data;
}
/**
* @return MetaResponse
*/
public function getMeta()
{
return $this->meta;
}
/**
* @param MetaResponse $meta
*/
public function setMeta(MetaResponse $meta)
{
$this->meta = $meta;
}
/**
* @return LinksResponse
*/
public function getLinks()
{
return $this->links;
}
/**
* @param LinksResponse $links
*/
public function setLinks(LinksResponse $links)
{
$this->links = $links;
}
/**
* @inheritdoc
*/
public function jsonSerialize()
{
$response = [
'data' => $this->getData()
];
if (!$this->getData() && !$this->getMeta()) {
$this->setMeta(new MetaResponse(['message' => 'Request was successful, but there is no result']));
}
if ($this->getMeta()) {
$response = ['meta' => $this->getMeta()] + $response;
}
if ($this->getLinks()) {
$response['links'] = $this->getLinks();
}
return $response;
}
}