-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcursor_pagination_profile.php
More file actions
38 lines (27 loc) · 981 Bytes
/
cursor_pagination_profile.php
File metadata and controls
38 lines (27 loc) · 981 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
33
34
35
36
37
38
<?php
declare(strict_types=1);
use alsvanzelf\jsonapi\CollectionDocument;
use alsvanzelf\jsonapi\objects\ResourceObject;
use alsvanzelf\jsonapi\profiles\CursorPaginationProfile;
require __DIR__.'/bootstrap_examples.php';
/**
* use the cursor pagination profile as extension to the document
*/
$profile = new CursorPaginationProfile();
$user1 = new ResourceObject('user', 1);
$user2 = new ResourceObject('user', 2);
$user42 = new ResourceObject('user', 42);
$profile->setCursor($user1, 'ford');
$profile->setCursor($user2, 'arthur');
$profile->setCursor($user42, 'zaphod');
$document = CollectionDocument::fromResources($user1, $user2, $user42);
$document->applyProfile($profile);
$profile->setCount($document, exactTotal: 3, bestGuessTotal: 10);
$profile->setLinksFirstPage($document, baseOrCurrentUrl: '/users?sort=42&page[size]=10', lastCursor: 'zaphod');
/**
* get the json
*/
$options = [
'prettyPrint' => true,
];
echo '<pre>'.$document->toJson($options);