|
1 | 1 | <?php declare(strict_types=1); |
| 2 | + |
2 | 3 | use JsonApiPhp\JsonApi\Attribute; |
3 | 4 | use JsonApiPhp\JsonApi\CompoundDocument; |
4 | 5 | use JsonApiPhp\JsonApi\Included; |
5 | 6 | use JsonApiPhp\JsonApi\Link\LastLink; |
6 | 7 | use JsonApiPhp\JsonApi\Link\NextLink; |
7 | 8 | use JsonApiPhp\JsonApi\Link\RelatedLink; |
8 | 9 | use JsonApiPhp\JsonApi\Link\SelfLink; |
9 | | -use JsonApiPhp\JsonApi\Link\Url; |
10 | | -use JsonApiPhp\JsonApi\MultiLinkage; |
11 | | -use JsonApiPhp\JsonApi\Relationship; |
| 10 | +use JsonApiPhp\JsonApi\PaginatedResourceCollection; |
| 11 | +use JsonApiPhp\JsonApi\Pagination; |
12 | 12 | use JsonApiPhp\JsonApi\ResourceIdentifier; |
| 13 | +use JsonApiPhp\JsonApi\ResourceIdentifierCollection; |
13 | 14 | use JsonApiPhp\JsonApi\ResourceObject; |
14 | | -use JsonApiPhp\JsonApi\ResourceObjectSet; |
15 | | -use JsonApiPhp\JsonApi\SingleLinkage; |
| 15 | +use JsonApiPhp\JsonApi\ToMany; |
| 16 | +use JsonApiPhp\JsonApi\ToOne; |
16 | 17 |
|
17 | 18 | require_once __DIR__.'/../vendor/autoload.php'; |
18 | 19 |
|
|
22 | 23 | new Attribute('first-name', 'Dan'), |
23 | 24 | new Attribute('last-name', 'Gebhardt'), |
24 | 25 | new Attribute('twitter', 'dgeb'), |
25 | | - new SelfLink(new Url('http://example.com/people/9')) |
| 26 | + new SelfLink('http://example.com/people/9') |
26 | 27 | ); |
27 | 28 |
|
28 | 29 | $comment05 = new ResourceObject( |
29 | 30 | 'comments', |
30 | 31 | '5', |
31 | 32 | new Attribute('body', 'First!'), |
32 | | - new SelfLink(new Url('http://example.com/comments/5')), |
33 | | - new Relationship('author', new SingleLinkage(new ResourceIdentifier('people', '2'))) |
| 33 | + new SelfLink('http://example.com/comments/5'), |
| 34 | + new ToOne('author', new ResourceIdentifier('people', '2')) |
34 | 35 |
|
35 | 36 | ); |
36 | 37 | $comment12 = new ResourceObject( |
37 | 38 | 'comments', |
38 | 39 | '12', |
39 | 40 | new Attribute('body', 'I like XML better'), |
40 | | - new SelfLink(new Url('http://example.com/comments/12')), |
41 | | - new Relationship('author', new SingleLinkage($dan->identifier())) |
| 41 | + new SelfLink('http://example.com/comments/12'), |
| 42 | + new ToOne('author', $dan->toIdentifier()) |
42 | 43 | ); |
43 | 44 |
|
44 | 45 | $document = new CompoundDocument( |
45 | | - new ResourceObjectSet( |
| 46 | + new PaginatedResourceCollection( |
| 47 | + new Pagination( |
| 48 | + new NextLink('http://example.com/articles?page[offset]=2'), |
| 49 | + new LastLink('http://example.com/articles?page[offset]=10') |
| 50 | + ), |
46 | 51 | new ResourceObject( |
47 | 52 | 'articles', |
48 | 53 | '1', |
49 | 54 | new Attribute('title', 'JSON API paints my bikeshed!'), |
50 | | - new SelfLink(new Url('http://example.com/articles/1')), |
51 | | - new Relationship( |
| 55 | + new SelfLink('http://example.com/articles/1'), |
| 56 | + new ToOne( |
52 | 57 | 'author', |
53 | | - new SingleLinkage($dan->identifier()), |
54 | | - new SelfLink(new Url('http://example.com/articles/1/relationships/author')), |
55 | | - new RelatedLink(new Url('http://example.com/articles/1/author')) |
| 58 | + $dan->toIdentifier(), |
| 59 | + new SelfLink('http://example.com/articles/1/relationships/author'), |
| 60 | + new RelatedLink('http://example.com/articles/1/author') |
56 | 61 | ), |
57 | | - new Relationship( |
| 62 | + new ToMany( |
58 | 63 | 'comments', |
59 | | - new MultiLinkage( |
60 | | - $comment05->identifier(), |
61 | | - $comment12->identifier() |
| 64 | + new ResourceIdentifierCollection( |
| 65 | + $comment05->toIdentifier(), |
| 66 | + $comment12->toIdentifier() |
62 | 67 | ), |
63 | | - new SelfLink(new Url('http://example.com/articles/1/relationships/comments')), |
64 | | - new RelatedLink(new Url('http://example.com/articles/1/comments')) |
| 68 | + new SelfLink('http://example.com/articles/1/relationships/comments'), |
| 69 | + new RelatedLink('http://example.com/articles/1/comments') |
65 | 70 | ) |
66 | 71 | ) |
67 | 72 | ), |
68 | 73 | new Included($dan, $comment05, $comment12), |
69 | | - new SelfLink(new Url('http://example.com/articles')), |
70 | | - new NextLink(new Url('http://example.com/articles?page[offset]=2')), |
71 | | - new LastLink(new Url('http://example.com/articles?page[offset]=10')) |
| 74 | + new SelfLink('http://example.com/articles') |
72 | 75 | ); |
73 | 76 |
|
74 | 77 | echo json_encode($document, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
0 commit comments