X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Ffunctions.php;h=9130fd40b53074d1cc46cf97605acde67e4a6b65;hb=2121556150be871684b5046af7cf250b8219128d;hp=9776da9b696f7c719b05b676c970c69e092e5fc0;hpb=2895e1945b9029f54546ae7f53afbe19070b65ac;p=m6w6%2Fseekat diff --git a/lib/functions.php b/lib/functions.php index 9776da9..9130fd4 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1,99 +1,28 @@ expand($str, $arr); + } } - return $type; } -namespace seekat\Exception; - -/** - * Canonicalize an error message from a string or Exception - * @param string|Exception $error - * @return string - */ -function message(&$error) : string { - if ($error instanceof \Throwable) { - $message = $error->getMessage(); - } else { - $message = $error; - $error = new \Exception($error); +namespace seekat { + /** + * Generate a human readable representation of a variable + * @param mixed $arg + * @param bool $export whether to var_export the $arg + * @return string + */ + function typeof($arg, $export = false) { + $type = is_object($arg) + ? "instance of ".get_class($arg) + : gettype($arg); + if ($export) { + $type .= ": ".var_export($arg, true); + } + return $type; } - return $message; } - -namespace seekat\API\Links; - -use React\Promise\{ - ExtendedPromiseInterface, - function reject -}; -use seekat\API; -use seekat\API\Call\Cache; - -/** - * Perform a GET request against the link's "first" relation - * - * @return ExtendedPromiseInterface - */ -function first(API $api, Cache\Service $cache = null) : ExtendedPromiseInterface { - $links = $api->getLinks(); - if ($links && ($first = $links->getFirst())) { - return $api->withUrl($first)->get(null, null, $cache); - } - return reject($links); -} - -/** - * Perform a GET request against the link's "prev" relation - * - * @return ExtendedPromiseInterface - */ -function prev(API $api, Cache\Service $cache = null) : ExtendedPromiseInterface { - $links = $api->getLinks(); - if ($links && ($prev = $links->getPrev())) { - return $api->withUrl($prev)->get(null, null, $cache); - } - return reject($links); -} - -/** - * Perform a GET request against the link's "next" relation - * - * @return ExtendedPromiseInterface - */ -function next(API $api, Cache\Service $cache = null) : ExtendedPromiseInterface { - $links = $api->getLinks(); - if ($links && ($next = $links->getNext())) { - return $api->withUrl($next)->get(null, null, $cache); - } - return reject($links); -} - -/** - * Perform a GET request against the link's "last" relation - * - * @return ExtendedPromiseInterface - */ -function last(API $api, Cache\Service $cache = null) : ExtendedPromiseInterface { - $links = $api->getLinks(); - if ($links && ($last = $links->getLast())) { - return $api->withUrl($last)->get(null, null, $cache); - } - return reject($links); -} -