1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Services; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Contracts\RouteContract; |
6
|
|
|
use Hyde\Framework\Contracts\RoutingServiceContract; |
7
|
|
|
use Hyde\Framework\Hyde; |
8
|
|
|
use Hyde\Framework\RouteCollection; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Pseudo-Router for Hyde. |
12
|
|
|
* |
13
|
|
|
* This is not a router in the traditional sense that it decides where to go. |
14
|
|
|
* Instead, it creates a pre-generated object encapsulating the Hyde autodiscovery. |
15
|
|
|
* |
16
|
|
|
* This not only let us emulate Laravel route helpers, but also serve as the |
17
|
|
|
* canonical source of truth for the vital HydePHP autodiscovery process. |
18
|
|
|
* |
19
|
|
|
* The routes defined can then also be used to power the RealtimeCompiler without |
20
|
|
|
* having to reverse-engineer the source file mapping. |
21
|
|
|
* |
22
|
|
|
* Routes cannot be added manually, instead the route index is created using the |
23
|
|
|
* exact same rules as the current autodiscovery process and compiled file output. |
24
|
|
|
* |
25
|
|
|
* The route index serves as a multidimensional mapping allowing you to |
26
|
|
|
* determine where a source file will be compiled to, and where a compiled |
27
|
|
|
* file was generated from. |
28
|
|
|
* |
29
|
|
|
* @see \Hyde\Framework\Testing\Feature\RoutingServiceTest |
30
|
|
|
*/ |
31
|
|
|
class RoutingService implements RoutingServiceContract |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @deprecated |
35
|
|
|
* @inheritDoc |
36
|
|
|
*/ |
37
|
|
|
public static function getInstance(): self |
38
|
|
|
{ |
39
|
|
|
return new self(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get all routes discovered by the autodiscovery process. |
44
|
|
|
* |
45
|
|
|
* @return \Hyde\Framework\RouteCollection<\Hyde\Framework\Contracts\RouteContract> |
46
|
|
|
*/ |
47
|
|
|
public function getRoutes(): RouteCollection |
48
|
|
|
{ |
49
|
|
|
return Hyde::routes(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get all discovered routes for the given page class. |
54
|
|
|
* |
55
|
|
|
* @param class-string<\Hyde\Framework\Contracts\PageContract> $pageClass |
|
|
|
|
56
|
|
|
* @return \Hyde\Framework\RouteCollection<\Hyde\Framework\Contracts\RouteContract> |
57
|
|
|
*/ |
58
|
|
|
public function getRoutesForModel(string $pageClass): RouteCollection |
59
|
|
|
{ |
60
|
|
|
return Hyde::routes()->getRoutesForModel($pageClass); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Add a route to the router index. |
65
|
|
|
* |
66
|
|
|
* This internal method adds the specified route to the route index. |
67
|
|
|
* It's intended to be used for package developers to hook into the routing system. |
68
|
|
|
* |
69
|
|
|
* @param \Hyde\Framework\Contracts\RouteContract $route |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function addRoute(RouteContract $route): static |
73
|
|
|
{ |
74
|
|
|
Hyde::routes()->addRoute($route); |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.