Skip to content

Update README #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ A simple example to illustrate the general idea. This JSON representation from
}
}
```
can be built with the following php code (less imports):
can be built with the following php code:
<!-- assert=output expect=my_json -->
```php
<?php
$articles = new \JsonApiPhp\JsonApi\Document\Resource\ResourceObject('articles', '1');
$author = \JsonApiPhp\JsonApi\Document\Resource\Relationship::fromLinkage(
new \JsonApiPhp\JsonApi\Document\Resource\Linkage\SingleLinkage(
new \JsonApiPhp\JsonApi\Document\Resource\ResourceIdentifier('people', '9')
)
);
use \JsonApiPhp\JsonApi\Document;
use \JsonApiPhp\JsonApi\Document\Resource\{
Linkage\SingleLinkage, Relationship, ResourceIdentifier, ResourceObject
};

$author = Relationship::fromLinkage(new SingleLinkage(new ResourceIdentifier('people', '9')));
$author->setLink('self', '/articles/1/relationships/author');
$author->setLink('related','/articles/1/author');
$author->setLink('related', '/articles/1/author');
$articles = new ResourceObject('articles', '1');
$articles->setRelationship('author', $author);
$articles->setAttribute('title', 'Rails is Omakase');
$doc = \JsonApiPhp\JsonApi\Document::fromResource($articles);
echo json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo json_encode(Document::fromResource($articles), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
```

Please refer to [the tests](./test) for the full API documentation:
Expand Down