9776da9b696f7c719b05b676c970c69e092e5fc0
6 * Generate a human readable represenation of a variable
8 * @param bool $export whether to var_export the $arg
11 function typeof($arg, $export = false) {
12 $type = (is_object($arg)
13 ?
"instance of ".get_class($arg)
17 $type .= ": ".var_export($arg, true);
22 namespace seekat\Exception
;
25 * Canonicalize an error message from a string or Exception
26 * @param string|Exception $error
29 function message(&$error) : string {
30 if ($error instanceof \Throwable
) {
31 $message = $error->getMessage();
34 $error = new \
Exception($error);
39 namespace seekat\API\Links
;
42 ExtendedPromiseInterface
,
46 use seekat\API\Call\Cache
;
49 * Perform a GET request against the link's "first" relation
51 * @return ExtendedPromiseInterface
53 function first(API
$api, Cache\Service
$cache = null) : ExtendedPromiseInterface
{
54 $links = $api->getLinks();
55 if ($links && ($first = $links->getFirst())) {
56 return $api->withUrl($first)->get(null, null, $cache);
58 return reject($links);
62 * Perform a GET request against the link's "prev" relation
64 * @return ExtendedPromiseInterface
66 function prev(API
$api, Cache\Service
$cache = null) : ExtendedPromiseInterface
{
67 $links = $api->getLinks();
68 if ($links && ($prev = $links->getPrev())) {
69 return $api->withUrl($prev)->get(null, null, $cache);
71 return reject($links);
75 * Perform a GET request against the link's "next" relation
77 * @return ExtendedPromiseInterface
79 function next(API
$api, Cache\Service
$cache = null) : ExtendedPromiseInterface
{
80 $links = $api->getLinks();
81 if ($links && ($next = $links->getNext())) {
82 return $api->withUrl($next)->get(null, null, $cache);
84 return reject($links);
88 * Perform a GET request against the link's "last" relation
90 * @return ExtendedPromiseInterface
92 function last(API
$api, Cache\Service
$cache = null) : ExtendedPromiseInterface
{
93 $links = $api->getLinks();
94 if ($links && ($last = $links->getLast())) {
95 return $api->withUrl($last)->get(null, null, $cache);
97 return reject($links);