[OPTIMISATIONS] Optimised code and removed unused references

This commit is contained in:
Simon Sessingø
2016-04-09 05:58:18 +02:00
parent b34738a51a
commit 2f2c3ca3ca
6 changed files with 13 additions and 6 deletions
+1 -1
View File
@@ -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. 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 ```php
@@ -79,10 +79,12 @@ class RouterController extends RouterEntry {
/** /**
* @param string $url * @param string $url
* @return static
*/ */
public function setUrl($url) { public function setUrl($url) {
$url = rtrim($url, '/') . '/'; $url = rtrim($url, '/') . '/';
$this->url = $url; $this->url = $url;
return $this;
} }
/** /**
@@ -94,9 +96,11 @@ class RouterController extends RouterEntry {
/** /**
* @param string $controller * @param string $controller
* @return static
*/ */
public function setController($controller) { public function setController($controller) {
$this->controller = $controller; $this->controller = $controller;
return $this;
} }
/** /**
@@ -108,9 +112,11 @@ class RouterController extends RouterEntry {
/** /**
* @param string $method * @param string $method
* @return static
*/ */
public function setMethod($method) { public function setMethod($method) {
$this->method = $method; $this->method = $method;
return $this;
} }
} }
+1 -3
View File
@@ -123,7 +123,7 @@ abstract class RouterEntry {
} }
/** /**
* @return string * @return string|array
*/ */
public function getMiddleware() { public function getMiddleware() {
return $this->middleware; return $this->middleware;
@@ -360,9 +360,7 @@ abstract class RouterEntry {
} }
public function renderRoute(Request $request) { public function renderRoute(Request $request) {
if(is_object($this->getCallback()) && is_callable($this->getCallback())) { if(is_object($this->getCallback()) && is_callable($this->getCallback())) {
// When the callback is a function // When the callback is a function
call_user_func_array($this->getCallback(), $this->getParameters()); call_user_func_array($this->getCallback(), $this->getParameters());
} else { } else {
@@ -109,10 +109,12 @@ class RouterResource extends RouterEntry {
/** /**
* @param string $url * @param string $url
* @return static
*/ */
public function setUrl($url) { public function setUrl($url) {
$url = rtrim($url, '/') . '/'; $url = rtrim($url, '/') . '/';
$this->url = $url; $this->url = $url;
return $this;
} }
/** /**
@@ -124,9 +126,11 @@ class RouterResource extends RouterEntry {
/** /**
* @param string $controller * @param string $controller
* @return static
*/ */
public function setController($controller) { public function setController($controller) {
$this->controller = $controller; $this->controller = $controller;
return $this;
} }
} }
-1
View File
@@ -2,7 +2,6 @@
namespace Pecee\SimpleRouter; namespace Pecee\SimpleRouter;
use Pecee\ArrayUtil;
use Pecee\Http\Request; use Pecee\Http\Request;
class RouterRoute extends RouterEntry { class RouterRoute extends RouterEntry {
+1 -1
View File
@@ -16,7 +16,7 @@ class SimpleRouter {
/** /**
* Start/route request * Start/route request
* @param null $defaultNamespace * @param null $defaultNamespace
* @throws RouterException * @throws \Pecee\Exception\RouterException
*/ */
public static function start($defaultNamespace = null) { public static function start($defaultNamespace = null) {
$router = RouterBase::getInstance(); $router = RouterBase::getInstance();