Passed
Push — master ( 8a4bfa...c8e4ff )
by Caen
03:47 queued 13s
created

Routes::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 3
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Foundation\Facades;
6
7
use Hyde\Foundation\HydeKernel;
8
use Hyde\Foundation\Kernel\RouteCollection;
9
use Hyde\Hyde;
10
use Hyde\Support\Models\Route;
11
use Hyde\Support\Models\RouteKey;
12
use Illuminate\Support\Facades\Facade;
13
14
/**
15
 * Provides an easy way to access the Hyde pseudo-router.
16
 *
17
 * To access a route you need the route key which is the equivalent of the URL path of the compiled page.
18
 *
19
 * @mixin \Hyde\Foundation\Kernel\RouteCollection
20
 */
21
class Routes extends Facade
22
{
23
    /** @return \Hyde\Foundation\Kernel\RouteCollection<string, \Hyde\Support\Models\Route> */
24
    public static function getFacadeRoot(): RouteCollection
25
    {
26
        return HydeKernel::getInstance()->routes();
27
    }
28
29
    public static function exists(string $routeKey): bool
30
    {
31
        return static::getFacadeRoot()->has(RouteKey::normalize($routeKey));
32
    }
33
34
    public static function get(string $routeKey): ?Route
35
    {
36
        return static::getFacadeRoot()->get(RouteKey::normalize($routeKey));
37
    }
38
39
    /** @throws \Hyde\Framework\Exceptions\RouteNotFoundException */
40
    public static function getOrFail(string $routeKey): Route
41
    {
42
        return static::getFacadeRoot()->getRoute(RouteKey::normalize($routeKey));
43
    }
44
45
    /** @return \Hyde\Foundation\Kernel\RouteCollection<\Hyde\Support\Models\Route> */
46
    public static function all(): RouteCollection
47
    {
48
        return static::getFacadeRoot()->getRoutes();
49
    }
50
51
    /** Get the current route for the page being rendered. */
52
    public static function current(): ?Route
53
    {
54
        return Hyde::currentRoute();
55
    }
56
}
57