mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00: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;
|
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.
|
* Find url that matches method, parameters or name.
|
||||||
* Used when calling the url() helper.
|
* 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.
|
* Sets the router name, which makes it easier to obtain the url or router at a later point.
|
||||||
* Alias for LoadableRoute::setName().
|
* Alias for LoadableRoute::setName().
|
||||||
*
|
*
|
||||||
* @see LoadableRoute::setName()
|
|
||||||
* @param string|array $name
|
* @param string|array $name
|
||||||
* @return static
|
* @return static
|
||||||
|
* @see LoadableRoute::setName()
|
||||||
*/
|
*/
|
||||||
public function name($name): ILoadableRoute
|
public function name($name): ILoadableRoute
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
|
|||||||
|
|
||||||
public function matchRoute(string $url, Request $request): bool
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
|||||||
|
|
||||||
public function matchRoute(string $url, Request $request): bool
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user