3 namespace seekat\API\Links
;
5 use AsyncInterop\Promise
;
7 use seekat\API\Call\Cache
;
11 * Perform a GET request against the link's "first" relation
15 function first(API
$api, Cache\Service
$cache = null) : Promise
{
16 $links = $api->getLinks();
17 if ($links && ($first = $links->getFirst())) {
18 return $api->withUrl($first)->get(null, null, $cache);
20 return Future\reject
($api->getFuture(), $links);
24 * Perform a GET request against the link's "prev" relation
28 function prev(API
$api, Cache\Service
$cache = null) : Promise
{
29 $links = $api->getLinks();
30 if ($links && ($prev = $links->getPrev())) {
31 return $api->withUrl($prev)->get(null, null, $cache);
33 return Future\reject
($api->getFuture(), $links);
37 * Perform a GET request against the link's "next" relation
41 function next(API
$api, Cache\Service
$cache = null) : Promise
{
42 $links = $api->getLinks();
43 if ($links && ($next = $links->getNext())) {
44 return $api->withUrl($next)->get(null, null, $cache);
46 return Future\reject
($api->getFuture(), $links);
50 * Perform a GET request against the link's "last" relation
54 function last(API
$api, Cache\Service
$cache = null) : Promise
{
55 $links = $api->getLinks();
56 if ($links && ($last = $links->getLast())) {
57 return $api->withUrl($last)->get(null, null, $cache);
59 return Future\reject
($api->getFuture(), $links);