@@ -27,22 +27,22 @@ A simple example to illustrate the general idea. This JSON representation from
2727 }
2828}
2929```
30- can be built with the following php code (less imports) :
30+ can be built with the following php code:
3131<!-- assert=output expect=my_json -->
3232``` php
3333<?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')) );
4040$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');
4243$articles->setRelationship('author', $author);
4344$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);
4646```
4747
4848Please refer to [ the tests] ( ./test ) for the full API documentation:
0 commit comments