mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
RouteResource: simplified the findUrl method (issue: #666)
This commit is contained in:
@@ -91,6 +91,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
$parameters = array_fill_keys($matches[1], null);
|
||||
}
|
||||
}
|
||||
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -68,15 +68,19 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
||||
*/
|
||||
public function findUrl(?string $method = null, $parameters = null, ?string $name = null): string
|
||||
{
|
||||
$url = parent::findUrl($method, $parameters, $name);
|
||||
$url = array_search($name, $this->names, true);
|
||||
|
||||
$action = array_search($name, $this->names, true);
|
||||
$parametersUrl = '';
|
||||
|
||||
if ($action !== false) {
|
||||
return $url . $this->urls[$action];
|
||||
if ($parameters !== null && count($parameters) > 0) {
|
||||
$parametersUrl = join('/', $parameters) . '/';
|
||||
}
|
||||
|
||||
return $url;
|
||||
if ($url !== false) {
|
||||
return rtrim($this->url . $parametersUrl . $this->urls[$url], '/') . '/';
|
||||
}
|
||||
|
||||
return $this->url . $parametersUrl;
|
||||
}
|
||||
|
||||
protected function call($method): bool
|
||||
|
||||
Reference in New Issue
Block a user