@@ -69,30 +69,54 @@ public static function run()
69
69
$ request_uri = $ _SERVER ['REQUEST_URI ' ];
70
70
71
71
// Use a fast routing algorithm, such as the Radix tree, to match the request URI with the route items
72
+ $ matchedRoute = null ;
73
+
72
74
foreach (self ::getRoutes () as $ route ) {
73
75
if ($ route ->match ($ request_method , $ request_uri )) {
76
+ // If a route matches, check if it has parameters and continue searching for matches
77
+ if (!empty ($ route ->getParams ())) {
78
+ $ matchedRoute = $ route ;
79
+ continue ;
80
+ }
81
+
82
+ // If a route matches and has no parameters, execute it immediately
74
83
$ route ->execute ();
75
84
return ;
76
85
}
77
86
}
78
87
88
+ // If a route with parameters matched, execute it
89
+ if ($ matchedRoute !== null ) {
90
+ $ matchedRoute ->execute ();
91
+ return ;
92
+ }
93
+
79
94
// If no route matches, return a 404 error
80
95
http_response_code (404 );
81
96
include_once (__DIR__ . "/../routes/errors/404.html " );
82
97
}
83
98
84
99
// Getters and setters for the private properties
85
-
86
100
public static function getRoutes ()
87
101
{
88
102
return self ::$ routes ;
89
103
}
90
104
105
+ public static function setRoutes ($ routes )
106
+ {
107
+ self ::$ routes = $ routes ;
108
+ }
109
+
91
110
public static function setPrefix ($ prefix )
92
111
{
93
112
self ::$ prefix = $ prefix ;
94
113
}
95
114
115
+ public static function getPrefix ()
116
+ {
117
+ return self ::$ prefix ;
118
+ }
119
+
96
120
// Helper function to prefix a path with the global prefix
97
121
98
122
public static function prefixPath ($ path , $ prefix = null )
0 commit comments