@@ -69,30 +69,54 @@ public static function run()
6969 $ request_uri = $ _SERVER ['REQUEST_URI ' ];
7070
7171 // Use a fast routing algorithm, such as the Radix tree, to match the request URI with the route items
72+ $ matchedRoute = null ;
73+
7274 foreach (self ::getRoutes () as $ route ) {
7375 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
7483 $ route ->execute ();
7584 return ;
7685 }
7786 }
7887
88+ // If a route with parameters matched, execute it
89+ if ($ matchedRoute !== null ) {
90+ $ matchedRoute ->execute ();
91+ return ;
92+ }
93+
7994 // If no route matches, return a 404 error
8095 http_response_code (404 );
8196 include_once (__DIR__ . "/../routes/errors/404.html " );
8297 }
8398
8499 // Getters and setters for the private properties
85-
86100 public static function getRoutes ()
87101 {
88102 return self ::$ routes ;
89103 }
90104
105+ public static function setRoutes ($ routes )
106+ {
107+ self ::$ routes = $ routes ;
108+ }
109+
91110 public static function setPrefix ($ prefix )
92111 {
93112 self ::$ prefix = $ prefix ;
94113 }
95114
115+ public static function getPrefix ()
116+ {
117+ return self ::$ prefix ;
118+ }
119+
96120 // Helper function to prefix a path with the global prefix
97121
98122 public static function prefixPath ($ path , $ prefix = null )
0 commit comments