From 330143e5495f71e0502487f6afd0e1f104dab555 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 5 Sep 2021 19:23:14 +0100 Subject: [PATCH] [ROUTER][DOCUMENTATION] Add `Router::isAbsolute`, add documentation to `Router::url` and `s/setRouter/serServices/ --- src/Core/GNUsocial.php | 2 +- src/Core/Router/Router.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Core/GNUsocial.php b/src/Core/GNUsocial.php index c7e54b9e95..e4899145e5 100644 --- a/src/Core/GNUsocial.php +++ b/src/Core/GNUsocial.php @@ -171,7 +171,7 @@ class GNUsocial implements EventSubscriberInterface Form::setFactory($this->form_factory); Queue::setMessageBus($this->message_bus); Security::setHelper($this->security, $this->sanitizer); - Router::setRouter($this->router, $this->url_generator); + Router::setServices($this->router, $this->url_generator); HTTPClient::setClient($this->client); Formatting::setTwig($this->twig); Cache::setupCache(); diff --git a/src/Core/Router/Router.php b/src/Core/Router/Router.php index 13f67cc898..9276e94ea4 100644 --- a/src/Core/Router/Router.php +++ b/src/Core/Router/Router.php @@ -61,12 +61,22 @@ abstract class Router public static ?SRouter $router = null; public static ?UrlGeneratorInterface $url_gen = null; - public static function setRouter($rtr, $gen): void + public static function setServices($rtr, $gen): void { self::$router = $rtr; self::$url_gen = $gen; } + public static function isAbsolute(string $url) + { + return isset(parse_url($url)['host']); + } + + /** + * Generate a URL for route $id with $args replacing the + * placeholder route values. Extra params are added as query + * string to the URL + */ public static function url(string $id, array $args, int $type = self::ABSOLUTE_PATH): string { return self::$url_gen->generate($id, $args, $type);