Skip to content

Commit

Permalink
Close #230
Browse files Browse the repository at this point in the history
  • Loading branch information
neomerx committed Mar 2, 2019
1 parent 195c43e commit b97c5ac
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Representation/DocumentWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,42 @@ protected function getResourceRepresentation(ResourceInterface $resource, FieldS

$attributes = $this->getAttributesRepresentation($filter->getAttributes($resource));
if (empty($attributes) === false) {
\assert(
\json_encode($attributes) !== false,
'Attributes for resource type `' . $resource->getType() .
'` cannot be converted into JSON. Please check its Schema returns valid data.'
);
$representation[DocumentInterface::KEYWORD_ATTRIBUTES] = $attributes;
}

$relationships = $this->getRelationshipsRepresentation($filter->getRelationships($resource));
if (empty($relationships) === false) {
\assert(
\json_encode($relationships) !== false,
'Relationships for resource type `' . $resource->getType() .
'` cannot be converted into JSON. Please check its Schema returns valid data.'
);
$representation[DocumentInterface::KEYWORD_RELATIONSHIPS] = $relationships;
}

if ($resource->hasLinks() === true) {
$representation[DocumentInterface::KEYWORD_LINKS] =
$this->getLinksRepresentation($this->getUrlPrefix(), $resource->getLinks());
$links = $this->getLinksRepresentation($this->getUrlPrefix(), $resource->getLinks());
\assert(
\json_encode($links) !== false,
'Links for resource type `' . $resource->getType() .
'` cannot be converted into JSON. Please check its Schema returns valid data.'
);
$representation[DocumentInterface::KEYWORD_LINKS] = $links;
}

if ($resource->hasResourceMeta() === true) {
$representation[DocumentInterface::KEYWORD_META] = $resource->getResourceMeta();
$meta = $resource->getResourceMeta();
\assert(
\json_encode($meta) !== false,
'Meta for resource type `' . $resource->getType() .
'` cannot be converted into JSON. Please check its Schema returns valid data.'
);
$representation[DocumentInterface::KEYWORD_META] = $meta;
}

return $representation;
Expand Down

0 comments on commit b97c5ac

Please sign in to comment.