@@ -3,7 +3,7 @@ This library is an attempt to express business rules of JSON API specification i
3
3
4
4
A simple example to illustrate the general idea. This JSON representation from
5
5
[ the documentation] ( http://jsonapi.org/format/#document-resource-objects )
6
-
6
+ <!-- name=my_json -->
7
7
``` json
8
8
{
9
9
"data" : {
@@ -28,19 +28,20 @@ A simple example to illustrate the general idea. This JSON representation from
28
28
}
29
29
```
30
30
can be built with the following php code (less imports):
31
+ <!-- assert=output expect=my_json -->
31
32
``` php
32
33
<?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')
37
38
)
38
39
);
39
40
$author->setLink('self', '/articles/1/relationships/author');
40
41
$author->setLink('related','/articles/1/author');
41
42
$articles->setRelationship('author', $author);
42
43
$articles->setAttribute('title', 'Rails is Omakase');
43
- $doc = Document::fromResource($articles);
44
+ $doc = \JsonApiPhp\JsonApi\ Document::fromResource($articles);
44
45
echo json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
45
46
```
46
47
0 commit comments