8b3d4e555406e0600b9dd912be7faa44f0db22ff
[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, Cache\Service $cache = null) {
15 $links = $api->getLinks();
16 if ($links && ($first = $links->getFirst())) {
17 return $api->withUrl($first)->get(null, null, $cache);
18 }
19 return Future\resolve($api->getFuture(), null);
20 }
21
22 /**
23 * Perform a GET request against the link's "prev" relation
24 *
25 * @return mixed promise
26 */
27 function prev(API $api, Cache\Service $cache = null) {
28 $links = $api->getLinks();
29 if ($links && ($prev = $links->getPrev())) {
30 return $api->withUrl($prev)->get(null, null, $cache);
31 }
32 return Future\resolve($api->getFuture(), null);
33 }
34
35 /**
36 * Perform a GET request against the link's "next" relation
37 *
38 * @return mixed promise
39 */
40 function next(API $api, Cache\Service $cache = null) {
41 $links = $api->getLinks();
42 if ($links && ($next = $links->getNext())) {
43 return $api->withUrl($next)->get(null, null, $cache);
44 }
45 return Future\resolve($api->getFuture(), null);
46 }
47
48 /**
49 * Perform a GET request against the link's "last" relation
50 *
51 * @return mixed promise
52 */
53 function last(API $api, Cache\Service $cache = null) {
54 $links = $api->getLinks();
55 if ($links && ($last = $links->getLast())) {
56 return $api->withUrl($last)->get(null, null, $cache);
57 }
58 return Future\resolve($api->getFuture(), null);
59 }
60