Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Route
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 setRouter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRouter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasRouter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 url
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Router;
16
17/**
18 * Pop route class
19 *
20 * @category   Pop
21 * @package    Pop\Router
22 * @author     Nick Sagona, III <nick@popphp.org>
23 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
24 * @license    https://www.popphp.org/license     New BSD License
25 * @version    5.0.0
26 */
27class Route
28{
29
30    /**
31     * Router object
32     * @var ?Router
33     */
34    protected static ?Router $router = null;
35
36    /**
37     * Method to set the router
38     *
39     * @param  Router $router
40     * @return void
41     */
42    public static function setRouter(Router $router): void
43    {
44        static::$router = $router;
45    }
46
47    /**
48     * Method to get the router
49     *
50     * @return Router
51     */
52    public static function getRouter(): Router
53    {
54        return static::$router;
55    }
56
57    /**
58     * Method to check if the router has been registered
59     *
60     * @return bool
61     */
62    public static function hasRouter(): bool
63    {
64        return (static::$router !== null);
65    }
66
67    /**
68     * Get URL route string for the named route
69     *
70     * @param  string $routeName
71     * @param  mixed  $params
72     * @param  bool   $fqdn
73     * @throws Exception
74     * @return string
75     */
76    public static function url(string $routeName, mixed $params = null, bool $fqdn = false): string
77    {
78        if (!static::$router->hasName($routeName)) {
79            throw new Exception('Error: That route name does not exist.');
80        }
81
82        return static::$router->getUrl($routeName, $params, $fqdn);
83    }
84
85}