@@ -3,7 +3,7 @@ This library is an attempt to express business rules of JSON API specification i
33
44A simple example to illustrate the general idea. This JSON representation from
55[ the documentation] ( http://jsonapi.org/format/#document-resource-objects )
6-
6+ <!-- name=my_json -->
77``` json
88{
99 "data" : {
@@ -28,19 +28,20 @@ A simple example to illustrate the general idea. This JSON representation from
2828}
2929```
3030can be built with the following php code (less imports):
31+ <!-- assert=output expect=my_json -->
3132``` php
3233<?php
33- $articles = new ResourceObject('articles', '1');
34- $author = Relationship::fromLinkage(
35- new SingleLinkage(
36- new ResourceIdentifier('people', '9')
34+ $articles = new \JsonApiPhp\JsonApi\Document\Resource\ ResourceObject('articles', '1');
35+ $author = \JsonApiPhp\JsonApi\Document\Resource\ Relationship::fromLinkage(
36+ new \JsonApiPhp\JsonApi\Document\Resource\Linkage\ SingleLinkage(
37+ new \JsonApiPhp\JsonApi\Document\Resource\ ResourceIdentifier('people', '9')
3738 )
3839);
3940$author->setLink('self', '/articles/1/relationships/author');
4041$author->setLink('related','/articles/1/author');
4142$articles->setRelationship('author', $author);
4243$articles->setAttribute('title', 'Rails is Omakase');
43- $doc = Document::fromResource($articles);
44+ $doc = \JsonApiPhp\JsonApi\ Document::fromResource($articles);
4445echo json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
4546```
4647
0 commit comments