2020-06-05 06:00:34 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2020-06-05 06:00:34 +09:00
|
|
|
// {{{ License
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static wrapper for Symfony's router
|
|
|
|
*
|
|
|
|
* @package GNUsocial
|
|
|
|
* @category URL
|
|
|
|
*
|
2021-02-20 08:29:43 +09:00
|
|
|
* @author Hugo Sales <hugo@hsal.es>
|
|
|
|
* @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
|
2020-06-05 06:00:34 +09:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Core\Router;
|
|
|
|
|
2021-12-01 01:47:31 +09:00
|
|
|
use App\Core\Log;
|
2020-08-09 01:10:25 +09:00
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
2021-09-07 04:59:36 +09:00
|
|
|
use Symfony\Component\Routing\Router as SymfonyRouter;
|
2020-06-05 06:00:34 +09:00
|
|
|
|
2021-09-07 04:59:36 +09:00
|
|
|
/**
|
|
|
|
* @mixin SymfonyRouter
|
|
|
|
*/
|
2020-06-05 06:00:34 +09:00
|
|
|
abstract class Router
|
|
|
|
{
|
2020-08-09 01:10:25 +09:00
|
|
|
/**
|
|
|
|
* Generates an absolute URL, e.g. "http://example.com/dir/file".
|
|
|
|
*/
|
2021-10-10 17:26:18 +09:00
|
|
|
public const ABSOLUTE_URL = UrlGeneratorInterface::ABSOLUTE_URL;
|
2020-06-05 06:00:34 +09:00
|
|
|
|
2020-08-09 01:10:25 +09:00
|
|
|
/**
|
|
|
|
* Generates an absolute path, e.g. "/dir/file".
|
|
|
|
*/
|
2021-10-10 17:26:18 +09:00
|
|
|
public const ABSOLUTE_PATH = UrlGeneratorInterface::ABSOLUTE_PATH;
|
2020-08-09 01:10:25 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a relative path based on the current request path, e.g. "../parent-file".
|
|
|
|
*
|
|
|
|
* @see UrlGenerator::getRelativePath()
|
|
|
|
*/
|
2021-10-10 17:26:18 +09:00
|
|
|
public const RELATIVE_PATH = UrlGeneratorInterface::RELATIVE_PATH;
|
2020-08-09 01:10:25 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a network path, e.g. "//example.com/dir/file".
|
|
|
|
* Such reference reuses the current scheme but specifies the host.
|
|
|
|
*/
|
2021-10-10 17:26:18 +09:00
|
|
|
public const NETWORK_PATH = UrlGeneratorInterface::NETWORK_PATH;
|
2020-08-09 01:10:25 +09:00
|
|
|
|
2021-11-10 22:59:02 +09:00
|
|
|
public static ?SymfonyRouter $router = null;
|
2020-08-09 01:10:25 +09:00
|
|
|
|
2021-11-10 22:59:02 +09:00
|
|
|
public static function setRouter($rtr): void
|
2020-08-09 01:10:25 +09:00
|
|
|
{
|
2021-11-10 22:59:02 +09:00
|
|
|
self::$router = $rtr;
|
2020-08-09 01:10:25 +09:00
|
|
|
}
|
|
|
|
|
2021-09-06 03:23:14 +09:00
|
|
|
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
|
|
|
|
*/
|
2021-10-21 22:45:18 +09:00
|
|
|
public static function url(string $id, array $args = [], int $type = self::ABSOLUTE_PATH): string
|
2020-06-05 06:00:34 +09:00
|
|
|
{
|
2021-12-01 01:47:31 +09:00
|
|
|
if ($type === self::RELATIVE_PATH) {
|
|
|
|
Log::debug('Requested relative path which is not an absolute path... just saying...');
|
|
|
|
}
|
2021-11-10 22:59:02 +09:00
|
|
|
return self::$router->generate($id, $args, $type);
|
2020-06-05 06:00:34 +09:00
|
|
|
}
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
/**
|
|
|
|
* function match($url) throws Symfony\Component\Routing\Exception\ResourceNotFoundException
|
|
|
|
*/
|
2020-06-05 06:00:34 +09:00
|
|
|
public static function __callStatic(string $name, array $args)
|
|
|
|
{
|
|
|
|
return self::$router->{$name}(...$args);
|
|
|
|
}
|
|
|
|
}
|