1 | <?php |
||
11 | class RouteDefinitionProvider |
||
12 | { |
||
13 | /** @var array<int[]> List of static paths to route */ |
||
14 | protected $staticRoutes = []; |
||
15 | |||
16 | /** @var array<int[]> List of routes per number of segments */ |
||
17 | protected $segmentCounts = []; |
||
18 | |||
19 | /** @var array<array<int[]>> List of routes by each segment */ |
||
20 | protected $segmentValues = []; |
||
21 | |||
22 | /** @var array[] Cache of all route definitions */ |
||
23 | protected $routeDefinitions = []; |
||
24 | |||
25 | /** @var int[] List of routes by their name */ |
||
26 | protected $routesByName = []; |
||
27 | |||
28 | /** |
||
29 | * Adds a new route definition. |
||
30 | * @param RouteDefinition $definition A new route definition to add |
||
31 | */ |
||
32 | 18 | public function addRouteDefinition(RouteDefinition $definition): void |
|
58 | |||
59 | /** |
||
60 | * Returns PHP code for cached RouteDefinitionProvider that can be stored in file and included. |
||
61 | * @return string PHP code for cached RouteDefinitionProvider |
||
62 | */ |
||
63 | 18 | public function getCacheFile(): string |
|
83 | |||
84 | /** |
||
85 | * Returns route ids for routes with specific static path. |
||
86 | * @param string $path The static route path to search |
||
87 | * @return int[] List of route ids with specific static path |
||
88 | */ |
||
89 | 17 | public function getRoutesByStaticPath(string $path): array |
|
93 | |||
94 | /** |
||
95 | * Returns route ids with specific segment count. |
||
96 | * @param int $count The number of segments in the path |
||
97 | * @return int[] List of route ids with specific segment count |
||
98 | */ |
||
99 | 11 | public function getRoutesBySegmentCount(int $count): array |
|
103 | |||
104 | /** |
||
105 | * Returns route ids with specific value for specific segment. |
||
106 | * @param int $segment The number of the segment |
||
107 | * @param string $value The value for the segment or '/' dynamic segments |
||
108 | * @return int[] List of route ids the match the given criteria |
||
109 | */ |
||
110 | 8 | public function getRoutesBySegmentValue(int $segment, string $value): array |
|
114 | |||
115 | /** |
||
116 | * Returns a route definition by a specific id. |
||
117 | * @param int $routeId Id of the route definition |
||
118 | * @return RouteDefinition The route definition for the specific id |
||
119 | */ |
||
120 | 16 | public function getRouteDefinition(int $routeId): RouteDefinition |
|
128 | |||
129 | /** |
||
130 | * Returns a route definition by the name of the route. |
||
131 | * @param string $name The name of the route |
||
132 | * @return RouteDefinition The route definition with the given name |
||
133 | */ |
||
134 | 10 | public function getRouteDefinitionByName(string $name): RouteDefinition |
|
142 | } |
||
143 |