From 2f2c3ca3caaaab68eb9b36203a9809ef6531cc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Sat, 9 Apr 2016 05:58:18 +0200 Subject: [PATCH] [OPTIMISATIONS] Optimised code and removed unused references --- README.md | 2 +- src/Pecee/SimpleRouter/RouterController.php | 6 ++++++ src/Pecee/SimpleRouter/RouterEntry.php | 4 +--- src/Pecee/SimpleRouter/RouterResource.php | 4 ++++ src/Pecee/SimpleRouter/RouterRoute.php | 1 - src/Pecee/SimpleRouter/SimpleRouter.php | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b4ce627..fbc0d86 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ SimpleRouter::csrfVerifier(new \Demo\Middleware\CsrfVerifier()); Sometimes it can be necessary to keep urls stored in the database, file or similar. In this example, we want the url ```/my-cat-is-beatiful``` to load the route ```/article/view/1``` which the router knows, because it's defined in the ```routes.php``` file. -To interfere with the router, we create a class that inherits from ```RouterBootManager```. This class will be loaded before any other rules in ```routes.php``` and allow us to "change" the current route, if any of our criteria are fulfilled (like comming from the url ```/my-cat-is-beatiful```). +To interfere with the router, we create a class that inherits from ```RouterBootManager```. This class will be loaded before any other rules in ```routes.php``` and allow us to "change" the current route, if any of our criteria are fulfilled (like coming from the url ```/my-cat-is-beatiful```). ```php diff --git a/src/Pecee/SimpleRouter/RouterController.php b/src/Pecee/SimpleRouter/RouterController.php index 14230b5..bcb5cdc 100644 --- a/src/Pecee/SimpleRouter/RouterController.php +++ b/src/Pecee/SimpleRouter/RouterController.php @@ -79,10 +79,12 @@ class RouterController extends RouterEntry { /** * @param string $url + * @return static */ public function setUrl($url) { $url = rtrim($url, '/') . '/'; $this->url = $url; + return $this; } /** @@ -94,9 +96,11 @@ class RouterController extends RouterEntry { /** * @param string $controller + * @return static */ public function setController($controller) { $this->controller = $controller; + return $this; } /** @@ -108,9 +112,11 @@ class RouterController extends RouterEntry { /** * @param string $method + * @return static */ public function setMethod($method) { $this->method = $method; + return $this; } } \ No newline at end of file diff --git a/src/Pecee/SimpleRouter/RouterEntry.php b/src/Pecee/SimpleRouter/RouterEntry.php index 87e6b9f..3543e51 100644 --- a/src/Pecee/SimpleRouter/RouterEntry.php +++ b/src/Pecee/SimpleRouter/RouterEntry.php @@ -123,7 +123,7 @@ abstract class RouterEntry { } /** - * @return string + * @return string|array */ public function getMiddleware() { return $this->middleware; @@ -360,9 +360,7 @@ abstract class RouterEntry { } public function renderRoute(Request $request) { - if(is_object($this->getCallback()) && is_callable($this->getCallback())) { - // When the callback is a function call_user_func_array($this->getCallback(), $this->getParameters()); } else { diff --git a/src/Pecee/SimpleRouter/RouterResource.php b/src/Pecee/SimpleRouter/RouterResource.php index e2c1920..3ba17ad 100644 --- a/src/Pecee/SimpleRouter/RouterResource.php +++ b/src/Pecee/SimpleRouter/RouterResource.php @@ -109,10 +109,12 @@ class RouterResource extends RouterEntry { /** * @param string $url + * @return static */ public function setUrl($url) { $url = rtrim($url, '/') . '/'; $this->url = $url; + return $this; } /** @@ -124,9 +126,11 @@ class RouterResource extends RouterEntry { /** * @param string $controller + * @return static */ public function setController($controller) { $this->controller = $controller; + return $this; } } \ No newline at end of file diff --git a/src/Pecee/SimpleRouter/RouterRoute.php b/src/Pecee/SimpleRouter/RouterRoute.php index 8b11afa..86c0a8d 100644 --- a/src/Pecee/SimpleRouter/RouterRoute.php +++ b/src/Pecee/SimpleRouter/RouterRoute.php @@ -2,7 +2,6 @@ namespace Pecee\SimpleRouter; -use Pecee\ArrayUtil; use Pecee\Http\Request; class RouterRoute extends RouterEntry { diff --git a/src/Pecee/SimpleRouter/SimpleRouter.php b/src/Pecee/SimpleRouter/SimpleRouter.php index 6a4d671..4469aa0 100644 --- a/src/Pecee/SimpleRouter/SimpleRouter.php +++ b/src/Pecee/SimpleRouter/SimpleRouter.php @@ -16,7 +16,7 @@ class SimpleRouter { /** * Start/route request * @param null $defaultNamespace - * @throws RouterException + * @throws \Pecee\Exception\RouterException */ public static function start($defaultNamespace = null) { $router = RouterBase::getInstance();