mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-15 18:23:26 +03:00
Simplified RouteController and RouteResource by moving common group-match code to parent method.
This commit is contained in:
@@ -100,6 +100,18 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if group is defined and matches the given url.
|
||||
*
|
||||
* @param string $url
|
||||
* @param Request $request
|
||||
* @return bool
|
||||
*/
|
||||
protected function matchGroup(string $url, Request $request): bool
|
||||
{
|
||||
return ($this->getGroup() === null || $this->getGroup()->matchRoute($url, $request) === true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find url that matches method, parameters or name.
|
||||
* Used when calling the url() helper.
|
||||
@@ -203,9 +215,9 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
* Sets the router name, which makes it easier to obtain the url or router at a later point.
|
||||
* Alias for LoadableRoute::setName().
|
||||
*
|
||||
* @see LoadableRoute::setName()
|
||||
* @param string|array $name
|
||||
* @return static
|
||||
* @see LoadableRoute::setName()
|
||||
*/
|
||||
public function name($name): ILoadableRoute
|
||||
{
|
||||
|
||||
@@ -88,7 +88,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
|
||||
|
||||
public function matchRoute(string $url, Request $request): bool
|
||||
{
|
||||
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
|
||||
if ($this->matchGroup($url, $request) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
||||
|
||||
public function matchRoute(string $url, Request $request): bool
|
||||
{
|
||||
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
|
||||
if ($this->matchGroup($url, $request) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user