mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-15 18:23:26 +03:00
[OPTIMISATIONS] Optimised code and removed unused references
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Pecee\SimpleRouter;
|
||||
|
||||
use Pecee\ArrayUtil;
|
||||
use Pecee\Http\Request;
|
||||
|
||||
class RouterRoute extends RouterEntry {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user