update to PHP-8.1
[m6w6/seekat] / lib / functions.php
index 9e82d7200aef3ee44f6ca068bb29e6135f873874..8a1615be160d1cf9b9bc3037056b1296e120601e 100644 (file)
@@ -1,75 +1,28 @@
 <?php
 
-namespace seekat\Exception;
-
-function message(&$error) : string {
-       if ($error instanceof \Throwable) {
-               $message = $error->getMessage();
-       } else {
-               $message = $error;
-               $error = new \Exception($error);
+namespace {
+       if (!function_exists("uri_template")) {
+               function uri_template(string $str, array $arr = []) : string {
+                       $tpl = new \Rize\UriTemplate;
+                       return $tpl->expand($str, $arr);
+               }
        }
-       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);
+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, bool $export = false) : string {
+               $type = is_object($arg)
+                       ? "instance of ".get_class($arg)
+                       : gettype($arg);
+               if ($export) {
+                       $type .= ": ".var_export($arg, true);
+               }
+               return $type;
        }
-       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);
-}
-