mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
Fixed Route::setUrl() behavior
When there are no parameters in the url, correctly empty the routes parameter array
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user