[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

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.
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

View File

@@ -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;
}
}

View File

@@ -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 {

View File

@@ -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;
}
}

View File

@@ -2,7 +2,6 @@
namespace Pecee\SimpleRouter;
use Pecee\ArrayUtil;
use Pecee\Http\Request;
class RouterRoute extends RouterEntry {

View File

@@ -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();