Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
5 / 5 |
Router | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
5 / 5 |
setRouter | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
url | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
__callStatic | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
1 | <?php |
2 | |
3 | // {{{ License |
4 | // This file is part of GNU social - https://www.gnu.org/software/social |
5 | // |
6 | // GNU social is free software: you can redistribute it and/or modify |
7 | // it under the terms of the GNU Affero General Public License as published by |
8 | // the Free Software Foundation, either version 3 of the License, or |
9 | // (at your option) any later version. |
10 | // |
11 | // GNU social is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU Affero General Public License for more details. |
15 | // |
16 | // You should have received a copy of the GNU Affero General Public License |
17 | // along with GNU social. If not, see <http://www.gnu.org/licenses/>. |
18 | // }}} |
19 | |
20 | /** |
21 | * Static wrapper for Symfony's router |
22 | * |
23 | * @package GNUsocial |
24 | * @category URL |
25 | * |
26 | * @author Hugo Sales <hugo@hsal.es> |
27 | * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org |
28 | * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later |
29 | */ |
30 | |
31 | namespace App\Core\Router; |
32 | |
33 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
34 | use Symfony\Component\Routing\Router as SRouter; |
35 | |
36 | abstract class Router |
37 | { |
38 | /** |
39 | * Generates an absolute URL, e.g. "http://example.com/dir/file". |
40 | */ |
41 | const ABSOLUTE_URL = UrlGeneratorInterface::ABSOLUTE_URL; |
42 | |
43 | /** |
44 | * Generates an absolute path, e.g. "/dir/file". |
45 | */ |
46 | const ABSOLUTE_PATH = UrlGeneratorInterface::ABSOLUTE_PATH; |
47 | |
48 | /** |
49 | * Generates a relative path based on the current request path, e.g. "../parent-file". |
50 | * |
51 | * @see UrlGenerator::getRelativePath() |
52 | */ |
53 | const RELATIVE_PATH = UrlGeneratorInterface::RELATIVE_PATH; |
54 | |
55 | /** |
56 | * Generates a network path, e.g. "//example.com/dir/file". |
57 | * Such reference reuses the current scheme but specifies the host. |
58 | */ |
59 | const NETWORK_PATH = UrlGeneratorInterface::NETWORK_PATH; |
60 | |
61 | public static ?SRouter $router = null; |
62 | public static ?UrlGeneratorInterface $url_gen = null; |
63 | |
64 | public static function setRouter($rtr, $gen): void |
65 | { |
66 | self::$router = $rtr; |
67 | self::$url_gen = $gen; |
68 | } |
69 | |
70 | public static function url(string $id, array $args, int $type = self::ABSOLUTE_PATH): string |
71 | { |
72 | return self::$url_gen->generate($id, $args, $type); |
73 | } |
74 | |
75 | /** function match($url) throws Symfony\Component\Routing\Exception\ResourceNotFoundException */ |
76 | public static function __callStatic(string $name, array $args) |
77 | { |
78 | return self::$router->{$name}(...$args); |
79 | } |
80 | } |