From 99f869b57d769aa74bf9a54567ad1a5a757f64e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Thu, 17 Nov 2016 16:33:27 +0100 Subject: [PATCH] Updated documentation --- README.md | 14 +++++--------- src/Pecee/SimpleRouter/RouterBase.php | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 42ea1d0..403f5f4 100644 --- a/README.md +++ b/README.md @@ -381,15 +381,11 @@ $route->setMethod('hello'); It's only possible to change the route BEFORE the route has initially been loaded. If you want to redirect to another route, we highly recommend that you modify the `RouterEntry` object from a `Middleware` or `ExceptionHandler`, like the examples below. -#### Faking new route +#### Rewriting to new route The example below will cause the router to re-route the request with another url. We are using the `url()` helper function to get the uri to another route added in the `routes.php` file. - -This does require the `$request` object to be returned, otherwise the `request` object will be ignored by the router. -Using the example below will NOT inherit the rules from the other route. This means that IF you are faking a route that is enabled in `post`. - -**NOTE: Use this method if you want to fully load a route (middlewares, request-method etc. will be kept).** +**NOTE: Use this method if you want to fully load another route using it's settings (request method etc).** ```php @@ -401,8 +397,8 @@ use Pecee\SimpleRouter\RouterEntry; class CustomMiddleware implements Middleware { - public function handle(Request $request, RouterEntry &$route = null) { - return $request->setUri(url('home')); + public function handle(Request $request, RouterEntry &$route) { + $request->setUri(url('home')); } } @@ -427,7 +423,7 @@ use Pecee\SimpleRouter\RouterEntry; class CustomMiddleware implements Middleware { - public function handle(Request $request, RouterEntry &$route = null) { + public function handle(Request $request, RouterEntry &$route) { $route->callback('DefaultController@home'); } diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index 82bee7a..358ad29 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -222,7 +222,7 @@ class RouterBase { if ($route->matchRoute($this->request)) { - if (!in_array($this->request->getMethod(), $route->getRequestMethods())) { + if (count($route->getRequestMethods()) && !in_array($this->request->getMethod(), $route->getRequestMethods())) { $routeNotAllowed = true; continue; }