Skip to content

Commit

Permalink
Fix dynamic route detection (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Ilic <[email protected]>
  • Loading branch information
gigili authored Jul 9, 2021
1 parent 724b176 commit db05b80
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,16 @@ public function handle()
$arguments = [];
if ( $route === false ) {
$dynamic_routes = array_filter($this->routes[$method], fn($route) => !is_null($route['regex'] ?? NULL));
foreach ( $dynamic_routes as $dynamic_route ) {
foreach ( $dynamic_routes as $routePath => $dynamic_route ) {
$countRouteSlashes = count(explode("/", $routePath));
$countPathSlashes = count(explode('/', $path));

//TODO: Find a way to not check the number of / as it seems a bit hacky
if ( $countPathSlashes !== $countRouteSlashes ) continue;

if ( preg_match("/{$dynamic_route['regex']}/", $path) ) {
$route = $dynamic_route;

preg_match_all("/{$dynamic_route['regex']}/", $path, $matches);
if ( count($matches) > 1 ) array_shift($matches);
$matches = array_map(fn($m) => $m[0], $matches);
Expand Down

0 comments on commit db05b80

Please sign in to comment.