@@ -27,22 +27,22 @@ A simple example to illustrate the general idea. This JSON representation from
27
27
}
28
28
}
29
29
```
30
- can be built with the following php code (less imports) :
30
+ can be built with the following php code:
31
31
<!-- assert=output expect=my_json -->
32
32
``` php
33
33
<?php
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')
38
- )
39
- );
34
+ use \JsonApiPhp\JsonApi\Document;
35
+ use \JsonApiPhp\JsonApi\Document\Resource\{
36
+ Linkage\SingleLinkage, Relationship, ResourceIdentifier, ResourceObject
37
+ };
38
+
39
+ $author = Relationship::fromLinkage(new SingleLinkage(new ResourceIdentifier('people', '9')) );
40
40
$author->setLink('self', '/articles/1/relationships/author');
41
- $author->setLink('related','/articles/1/author');
41
+ $author->setLink('related', '/articles/1/author');
42
+ $articles = new ResourceObject('articles', '1');
42
43
$articles->setRelationship('author', $author);
43
44
$articles->setAttribute('title', 'Rails is Omakase');
44
- $doc = \JsonApiPhp\JsonApi\Document::fromResource($articles);
45
- echo json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
45
+ echo json_encode(Document::fromResource($articles), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
46
46
```
47
47
48
48
Please refer to [ the tests] ( ./test ) for the full API documentation:
0 commit comments