-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
32 lines (27 loc) · 979 Bytes
/
example.php
File metadata and controls
32 lines (27 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/*
* This file is part of `lemonphp/json-api` project.
*
* (c) 2017 LemonPHP Team
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
use Lemon\JsonApi\Document;
use Lemon\JsonApi\Document\Resource\Relationship\Linkage;
use Lemon\JsonApi\Document\Resource\Relationship\Relationship;
use Lemon\JsonApi\Document\Resource\ResourceIdentifier;
use Lemon\JsonApi\Document\Resource\ResourceObject;
include_once 'vendor/autoload.php';
$author = Relationship::fromLinkage(
Linkage::fromSingleIdentifier(
new ResourceIdentifier('people', '9')
)
);
$author->setLink('self', '/articles/1/relationships/author');
$author->setLink('related', '/articles/1/author');
$article = new ResourceObject('articles', '1');
$article->setAttribute('title', 'Rails is Omakase');
$article->setRelationship('author', $author);
$doc = Document::fromResource($article);
echo json_encode($doc, JSON_PRETTY_PRINT);