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