update to PHP-8.1
[m6w6/seekat] / lib / API / Links / functions.php
1 <?php
2
3 namespace seekat\API\Links;
4
5 use seekat\API;
6 use seekat\API\Call\Cache;
7 use seekat\API\Future;
8
9 /**
10 * Perform a GET request against the link's "first" relation
11 *
12 * @return mixed promise
13 */
14 function first(API $api) {
15 if (($first = $api->getLinks()?->getFirst())) {
16 return $api->withUrl($first)->get();
17 }
18 return $api->getFuture()->resolve(null);
19 }
20
21 /**
22 * Perform a GET request against the link's "prev" relation
23 *
24 * @return mixed promise
25 */
26 function prev(API $api) {
27 if (($prev = $api->getLinks()?->getPrev())) {
28 return $api->withUrl($prev)->get();
29 }
30 return $api->getFuture()->resolve(null);
31 }
32
33 /**
34 * Perform a GET request against the link's "next" relation
35 *
36 * @return mixed promise
37 */
38 function next(API $api) {
39 if (($next = $api->getLinks()?->getNext())) {
40 return $api->withUrl($next)->get();
41 }
42 return $api->getFuture()->resolve(null);
43 }
44
45 /**
46 * Perform a GET request against the link's "last" relation
47 *
48 * @return mixed promise
49 */
50 function last(API $api, Cache\Service $cache = null) {
51 $links = $api->getLinks();
52 if ($links && ($last = $links->getLast())) {
53 return $api->withUrl($last)->get(null, null, $cache);
54 }
55 return $api->getFuture()->resolve(null);
56 }
57