Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Routes
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 getFacadeRoot
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 exists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOrFail
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 all
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 current
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Hyde\Foundation\Facades;
6
7use Hyde\Foundation\HydeKernel;
8use Hyde\Foundation\Kernel\RouteCollection;
9use Hyde\Hyde;
10use Hyde\Support\Models\Route;
11use Illuminate\Support\Facades\Facade;
12
13/**
14 * Provides an easy way to access the Hyde pseudo-router.
15 *
16 * To access a route you need the route key which is the equivalent of the URL path of the compiled page.
17 *
18 * @mixin \Hyde\Foundation\Kernel\RouteCollection
19 */
20class Routes extends Facade
21{
22    public static function getFacadeRoot(): RouteCollection
23    {
24        return HydeKernel::getInstance()->routes();
25    }
26
27    public static function exists(string $routeKey): bool
28    {
29        return static::getFacadeRoot()->has($routeKey);
30    }
31
32    public static function get(string $routeKey): ?Route
33    {
34        return static::getFacadeRoot()->get($routeKey);
35    }
36
37    /** @throws \Hyde\Framework\Exceptions\RouteNotFoundException */
38    public static function getOrFail(string $routeKey): Route
39    {
40        return static::getFacadeRoot()->getRoute($routeKey);
41    }
42
43    public static function all(): RouteCollection
44    {
45        return static::getFacadeRoot()->getRoutes();
46    }
47
48    /** Get the current route for the page being rendered. */
49    public static function current(): ?Route
50    {
51        return Hyde::currentRoute();
52    }
53}