Skip to content

Commit

Permalink
Merge pull request #360 from skipperbent/v3-development
Browse files Browse the repository at this point in the history
Version 3.4.11.0
  • Loading branch information
skipperbent committed Feb 14, 2018
2 parents bbb8133 + 932dfbf commit 3ba9dd0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 46 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"simple-php-router",
"laravel",
"pecee",
"php"
"php",
"framework",
"url-handling",
"input-handler",
"routing-engine",
"request-handler"
],
"license": "MIT",
"support": {
Expand Down
1 change: 1 addition & 0 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @param string|array|null $parameters
* @param array|null $getParams
* @return string
* @throws \InvalidArgumentException
*/
function url($name = null, $parameters = null, $getParams = null)
{
Expand Down
10 changes: 1 addition & 9 deletions src/Pecee/SimpleRouter/Route/LoadableRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
*/
public function loadMiddleware(Request $request)
{
$max = count($this->getMiddlewares());

if ($max === 0) {
return;
}

for ($i = 0; $i < $max; $i++) {

$middleware = $this->getMiddlewares()[$i];
foreach ($this->getMiddlewares() as $middleware) {

if (is_object($middleware) === false) {
$middleware = $this->loadClass($middleware);
Expand Down
2 changes: 1 addition & 1 deletion src/Pecee/SimpleRouter/Route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public function setMiddlewares(array $middlewares)
}

/**
* @return string|array
* @return array
*/
public function getMiddlewares()
{
Expand Down
42 changes: 8 additions & 34 deletions src/Pecee/SimpleRouter/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
class Router
{

/**
* The instance of this class
* @var static
*/
protected static $instance;

/**
* Current request
* @var Request
Expand Down Expand Up @@ -119,15 +113,12 @@ public function addRoute(IRoute $route)
protected function processRoutes(array $routes, IGroupRoute $group = null, IRoute $parent = null)
{
// Loop through each route-request
$max = count($routes) - 1;

$exceptionHandlers = [];

$url = ($this->request->getRewriteUrl() !== null) ? $this->request->getRewriteUrl() : $this->request->getUri()->getPath();

for ($i = $max; $i >= 0; $i--) {

$route = $routes[$i];
foreach ($routes as $route) {

if ($parent !== null) {

Expand Down Expand Up @@ -202,15 +193,9 @@ protected function processRoutes(array $routes, IGroupRoute $group = null, IRout
public function loadRoutes()
{
/* Initialize boot-managers */
if (count($this->bootManagers) !== 0) {

$max = count($this->bootManagers) - 1;

/* @var $manager IRouterBootManager */
for ($i = $max; $i >= 0; $i--) {
$manager = $this->bootManagers[$i];
$manager->boot($this->request);
}
/* @var $manager IRouterBootManager */
foreach ($this->bootManagers as $manager) {
$manager->boot($this->request);
}

/* Loop through each route-request */
Expand Down Expand Up @@ -243,12 +228,9 @@ public function routeRequest($rewrite = false)

$url = ($this->request->getRewriteUrl() !== null) ? $this->request->getRewriteUrl() : $this->request->getUri()->getPath();

$max = count($this->processedRoutes) - 1;

/* @var $route ILoadableRoute */
for ($i = $max; $i >= 0; $i--) {
foreach ($this->processedRoutes as $key => $route) {

$route = $this->processedRoutes[$i];

/* If the route matches */
if ($route->matchRoute($url, $this->request) === true) {
Expand All @@ -273,7 +255,7 @@ public function routeRequest($rewrite = false)
$rewriteUrl = $this->request->getRewriteUrl();

if ($rewriteUrl !== null && $rewriteUrl !== $url) {
unset($this->processedRoutes[$i]);
unset($this->processedRoutes[$key]);
$this->processedRoutes = array_values($this->processedRoutes);

return $this->routeRequest(true);
Expand Down Expand Up @@ -388,12 +370,8 @@ public function arrayToParams(array $getParams = [], $includeEmpty = true)
*/
public function findRoute($name)
{
$max = count($this->processedRoutes) - 1;

/* @var $route ILoadableRoute */
for ($i = $max; $i >= 0; $i--) {

$route = $this->processedRoutes[$i];
foreach ($this->processedRoutes as $route) {

/* Check if the name matches with a name on the route. Should match either router alias or controller alias. */
if ($route->hasName($name)) {
Expand Down Expand Up @@ -492,12 +470,8 @@ public function getUrl($name = null, $parameters = null, $getParams = null)

/* Loop through all the routes to see if we can find a match */

$max = count($this->processedRoutes) - 1;

/* @var $route ILoadableRoute */
for ($i = $max; $i >= 0; $i--) {

$route = $this->processedRoutes[$i];
foreach ($this->processedRoutes as $route) {

/* Check if the route contains the name/alias */
if ($route->hasName($controller) === true) {
Expand Down
2 changes: 1 addition & 1 deletion src/Pecee/SimpleRouter/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public static function error(\Closure $callback)
* @param string|null $name
* @param string|array|null $parameters
* @param array|null $getParams
* @throws \Exception
* @throws \InvalidArgumentException
* @return string
*/
public static function getUrl($name = null, $parameters = null, $getParams = null)
Expand Down

0 comments on commit 3ba9dd0

Please sign in to comment.