[OPTIMISATION] Optimisations + bugfixes.

- Fixed references to Pecee framework.
- Fixed variables not being initialised before usage.
- Cleaned up duplicate checks.
- Other small optimisations and bugfixes.
This commit is contained in:
Simon Sessingø
2015-12-11 18:06:52 +01:00
parent cede827a45
commit 0bec524606
8 changed files with 33 additions and 24 deletions
+19 -10
View File
@@ -1,10 +1,8 @@
<?php
namespace Pecee\SimpleRouter;
use Pecee\ArrayUtil;
use Pecee\Http\Middleware\BaseCsrfVerifier;
use Pecee\Http\Request;
use Pecee\Url;
class RouterBase {
@@ -42,8 +40,8 @@ class RouterBase {
// Loop through each route-request
$activeGroup = null;
$routesCount = count($routes);
$mergedSettings = array();
/* @var $route RouterEntry */
for($i = 0; $i < $routesCount; $i++) {
@@ -123,7 +121,7 @@ class RouterBase {
$routeMatch = $route->matchRoute($this->request);
if($routeMatch && !($routeMatch instanceof RouterGroup)) {
if($routeMatch) {
if(count($route->getRequestMethods()) && !in_array($this->request->getMethod(), $route->getRequestMethods())) {
$routeNotAllowed = true;
@@ -132,9 +130,9 @@ class RouterBase {
$routeNotAllowed = false;
$this->loadedRoute = $routeMatch;
$routeMatch->loadMiddleware($this->request);
$routeMatch->renderRoute($this->request);
$this->loadedRoute = $route;
$route->loadMiddleware($this->request);
$route->renderRoute($this->request);
break;
}
}
@@ -221,6 +219,15 @@ class RouterBase {
return $this;
}
protected function getParamsToArray($query) {
$output = array();
if($query[0] === '?') {
$query = substr($query, 1);
}
parse_str($query, $output);
return $output;
}
protected function processUrl($route, $method = null, $parameters = null, $getParams = null) {
$url = '/' . trim($route->getUrl(), '/');
@@ -254,7 +261,7 @@ class RouterBase {
$url = rtrim($url, '/') . '/';
if($getParams !== null && count($getParams)) {
$url .= '?'.Url::arrayToParams($getParams);
$url .= '?' . $this->getParamsToArray($getParams);
}
return $url;
@@ -328,13 +335,15 @@ class RouterBase {
$url = array($controller);
if(is_array($parameters)) {
ArrayUtil::append($url, $parameters);
foreach($parameters as $key => $value) {
array_push($url,$value);
}
}
$url = '/' . trim(join('/', $url), '/') . '/';
if(is_array($getParams)) {
$url .= '?' . Url::arrayToParams($getParams);
$url .= '?' . $this->getParamsToArray($getParams);
}
return $url;