Skip to content

Commit

Permalink
fix: patch up optional dynamic params showing ""
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Dec 17, 2024
1 parent c028707 commit 842dcc6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,20 @@ public static function findRoute(
return trim(substr($match[0][0], 0, $matches[$index + 1][0][1] - $match[0][1]), '/');
}

// Temporary fix for optional parameters
if (($match[0][1] ?? 1) === -1 && ($match[0][0] ?? null) === '') {
return;
}

// We have no following parameters: return the whole lot
return isset($match[0][0]) ? trim($match[0][0], '/') : null;
}, $matches, array_keys($matches));

$paramsWithSlash = array_filter($params, function ($param) {
if (!$param) {
return false;
}

return strpos($param, '/') !== false;
});

Expand Down Expand Up @@ -860,6 +869,12 @@ private static function handle(?array $routes = null, bool $quitAfterRun = false

private static function invoke($handler, $params = [])
{
if (!empty($params)) {
$params = array_filter($params, function ($param) {
return $param !== null;
});
}

if (is_callable($handler)) {
call_user_func_array(
$handler,
Expand Down

0 comments on commit 842dcc6

Please sign in to comment.