Fixed Route::setUrl() behavior

When there are no parameters in the url, correctly empty the routes parameter array
This commit is contained in:
Pascal Pirschel
2023-05-05 13:40:38 +02:00
parent e105f266e3
commit b2851e41f1
3 changed files with 41 additions and 1 deletions
@@ -82,14 +82,16 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
{
$this->url = ($url === '/') ? '/' : '/' . trim($url, '/') . '/';
$parameters = [];
if (strpos($this->url, $this->paramModifiers[0]) !== false) {
$regex = sprintf(static::PARAMETERS_REGEX_FORMAT, $this->paramModifiers[0], $this->paramOptionalSymbol, $this->paramModifiers[1]);
if ((bool)preg_match_all('/' . $regex . '/u', $this->url, $matches) !== false) {
$this->parameters = array_fill_keys($matches[1], null);
$parameters = array_fill_keys($matches[1], null);
}
}
$this->parameters = $parameters;
return $this;
}