-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'cursor-pagination-profile' into 2.1.0
- Loading branch information
Showing
9 changed files
with
846 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
use alsvanzelf\jsonapi\CollectionDocument; | ||
use alsvanzelf\jsonapi\objects\ResourceObject; | ||
use alsvanzelf\jsonapi\profiles\CursorPaginationProfile; | ||
|
||
require '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, $currentUrl='/users?sort=42&page[size]=10', $lastCursor='zaphod'); | ||
|
||
/** | ||
* get the json | ||
*/ | ||
|
||
$options = [ | ||
'prettyPrint' => true, | ||
]; | ||
echo '<pre>'.$document->toJson($options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace alsvanzelf\jsonapi\interfaces; | ||
|
||
interface PaginableInterface { | ||
/** | ||
* @param string $previousHref optional | ||
* @param string $nextHref optional | ||
* @param string $firstHref optional | ||
* @param string $lastHref optional | ||
*/ | ||
public function setPaginationLinks($previousHref=null, $nextHref=null, $firstHref=null, $lastHref=null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.