mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-19 09:41:25 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dcbf59b305 | |||
| bc16388613 | |||
| d3ed3a61b5 | |||
| 969b64650e | |||
| c2cf2334e7 |
@@ -100,14 +100,6 @@ class RouterBase {
|
||||
// Loop through each route-request
|
||||
$this->processRoutes($this->routes);
|
||||
|
||||
// Make sure the urls is in the right order when comparing
|
||||
usort($this->controllerUrlMap, function($a, $b) {
|
||||
if(stripos($b->getUrl(), '{') !== false) {
|
||||
return $a->getUrl();
|
||||
}
|
||||
return strcmp($b->getUrl(), $a->getUrl());
|
||||
});
|
||||
|
||||
$routeNotAllowed = false;
|
||||
|
||||
/* @var $route RouterEntry */
|
||||
@@ -124,6 +116,7 @@ class RouterBase {
|
||||
$routeNotAllowed = false;
|
||||
|
||||
$this->loadedRoute = $routeMatch;
|
||||
$routeMatch->loadMiddleware($this->request);
|
||||
$routeMatch->renderRoute($this->request);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -179,9 +179,9 @@ abstract class RouterEntry {
|
||||
public function getMergeableSettings() {
|
||||
$settings = $this->settings;
|
||||
|
||||
if(isset($settings['middleware'])) {
|
||||
/*if(isset($settings['middleware'])) {
|
||||
unset($settings['middleware']);
|
||||
}
|
||||
}*/
|
||||
|
||||
if(isset($settings['prefix'])) {
|
||||
unset($settings['prefix']);
|
||||
@@ -243,7 +243,7 @@ abstract class RouterEntry {
|
||||
return new $name();
|
||||
}
|
||||
|
||||
protected function loadMiddleware(Request $request) {
|
||||
public function loadMiddleware(Request $request) {
|
||||
if($this->getMiddleware()) {
|
||||
$middleware = $this->loadClass($this->getMiddleware());
|
||||
if (!($middleware instanceof Middleware)) {
|
||||
@@ -256,8 +256,6 @@ abstract class RouterEntry {
|
||||
}
|
||||
|
||||
public function renderRoute(Request $request) {
|
||||
// Load middleware
|
||||
$this->loadMiddleware($request);
|
||||
|
||||
if(is_object($this->getCallback()) && is_callable($this->getCallback())) {
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class RouterGroup extends RouterEntry {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function matchRoute(Request $request) {
|
||||
public function renderRoute(Request $request) {
|
||||
// Check if request method is allowed
|
||||
|
||||
if(strtolower($request->getUri()) == strtolower($this->prefix) || stripos($request->getUri(), $this->prefix) === 0) {
|
||||
@@ -29,11 +29,17 @@ class RouterGroup extends RouterEntry {
|
||||
throw new RouterException('Method not allowed');
|
||||
}
|
||||
|
||||
return $this;
|
||||
$this->loadMiddleware($request);
|
||||
|
||||
return parent::renderRoute($request);
|
||||
}
|
||||
|
||||
// No match here, move on...
|
||||
return null;
|
||||
}
|
||||
|
||||
public function matchRoute(Request $request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,9 +20,6 @@ class RouterResource extends RouterEntry {
|
||||
}
|
||||
|
||||
public function renderRoute(Request $request) {
|
||||
// Load middleware
|
||||
$this->loadMiddleware($request);
|
||||
|
||||
if(is_object($this->getCallback()) && is_callable($this->getCallback())) {
|
||||
// When the callback is a function
|
||||
call_user_func_array($this->getCallback(), $this->getParameters());
|
||||
|
||||
@@ -49,7 +49,7 @@ class RouterRoute extends RouterEntry {
|
||||
// Check if url parameter count matches
|
||||
if(stripos($url, $routeMatch) === 0) {
|
||||
|
||||
$matches = true;
|
||||
$matches = (count(explode('/', rtrim($url, '/'))) == count(explode('/', rtrim($route, '/'))));
|
||||
|
||||
if($this->regexMatch) {
|
||||
$parameters = $this->parseParameters($url, true, $this->regexMatch);
|
||||
@@ -62,7 +62,7 @@ class RouterRoute extends RouterEntry {
|
||||
} else {
|
||||
|
||||
$url = explode('/', $url);
|
||||
$route = explode('/', $route);
|
||||
$route = explode('/', rtrim($route, '/'));
|
||||
|
||||
$parameters = array();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user