[ROUTER][DOCUMENTATION] Add `Router::isAbsolute`, add documentation to `Router::url` and `s/setRouter/serServices/

This commit is contained in:
Hugo Sales 2021-09-05 19:23:14 +01:00
parent 61d95265a9
commit 330143e549
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 12 additions and 2 deletions

View File

@ -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();

View File

@ -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);