diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 164610e..3cf5d38 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,7 +5,11 @@
+
+
+
+
@@ -22,11 +26,44 @@
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -34,53 +71,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -88,8 +80,8 @@
-
-
+
+
@@ -97,11 +89,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -109,36 +113,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- set
- hasParam
- csrf_token
- static function start
- fireEvents(
->setUrl
EVENT_LOAD
addRoute
@@ -157,13 +135,18 @@
matchRoute
->getValue
->find
- function find
+
Req
value(
file(
setUrl
TODO
input()->get
+
+ REQUEST_TYPE_
+
+ setDebugEnabled
+ debugEnabled
D:\Workspace\simple-php-router\src\Pecee\SimpleRouter\Route
@@ -226,16 +209,16 @@
-
+
+
+
-
-
@@ -308,7 +291,6 @@
-
@@ -378,10 +360,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -448,9 +444,9 @@
+
-
@@ -527,26 +523,13 @@
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -562,9 +545,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -582,26 +580,26 @@
-
+
-
-
+
+
-
+
-
-
+
-
+
-
+
+
@@ -781,9 +779,6 @@
-
-
-
@@ -794,13 +789,6 @@
-
-
-
-
-
-
-
@@ -848,13 +836,6 @@
-
-
-
-
-
-
-
@@ -876,16 +857,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -893,16 +864,9 @@
-
-
-
-
-
-
-
-
+
@@ -910,46 +874,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -957,22 +884,90 @@
-
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Pecee/Http/Input/InputHandler.php b/src/Pecee/Http/Input/InputHandler.php
index 6d38ec3..567a916 100644
--- a/src/Pecee/Http/Input/InputHandler.php
+++ b/src/Pecee/Http/Input/InputHandler.php
@@ -313,7 +313,7 @@ class InputHandler
}
}
- return ($filter !== null) ? array_intersect_key($output, array_flip($filter)) : $output;
+ return (\count($filter) > 0) ? array_intersect_key($output, array_flip($filter)) : $output;
}
/**
diff --git a/src/Pecee/SimpleRouter/Route/Route.php b/src/Pecee/SimpleRouter/Route/Route.php
index a8963de..80a3dce 100644
--- a/src/Pecee/SimpleRouter/Route/Route.php
+++ b/src/Pecee/SimpleRouter/Route/Route.php
@@ -18,6 +18,7 @@ abstract class Route implements IRoute
public const REQUEST_TYPE_PATCH = 'patch';
public const REQUEST_TYPE_OPTIONS = 'options';
public const REQUEST_TYPE_DELETE = 'delete';
+ public const REQUEST_TYPE_HEAD = 'head';
public static $requestTypes = [
self::REQUEST_TYPE_GET,
@@ -26,6 +27,7 @@ abstract class Route implements IRoute
self::REQUEST_TYPE_PATCH,
self::REQUEST_TYPE_OPTIONS,
self::REQUEST_TYPE_DELETE,
+ self::REQUEST_TYPE_HEAD,
];
/**
@@ -120,23 +122,25 @@ abstract class Route implements IRoute
protected function parseParameters($route, $url, $parameterRegex = null)
{
- $regex = null;
- if (strpos($route, $this->paramModifiers[0]) !== false) {
- $regex = sprintf(static::PARAMETERS_REGEX_FORMAT, $this->paramModifiers[0], $this->paramOptionalSymbol, $this->paramModifiers[1]);
- }
+ $regex = (strpos($route, $this->paramModifiers[0]) === false) ? null :
+ sprintf
+ (
+ static::PARAMETERS_REGEX_FORMAT,
+ $this->paramModifiers[0],
+ $this->paramOptionalSymbol,
+ $this->paramModifiers[1]
+ );
// Ensures that host names/domains will work with parameters
$url = '/' . ltrim($url, '/');
- $urlRegex = null;
+ $urlRegex = '';
$parameters = [];
if ($regex === null || (bool)preg_match_all('/' . $regex . '/u', $route, $parameters) === false) {
$urlRegex = preg_quote($route, '/');
} else {
- $urlParts = preg_split('/((\-?\/?)\{[^}]+\})/', $route);
-
- foreach ($urlParts as $key => $t) {
+ foreach (preg_split('/((\-?\/?)\{[^}]+\})/', $route) as $key => $t) {
$regex = '';
@@ -164,7 +168,7 @@ abstract class Route implements IRoute
}
}
- if ($urlRegex === null || (bool)preg_match(sprintf($this->urlRegex, $urlRegex), $url, $matches) === false) {
+ if (trim($urlRegex) === '' || (bool)preg_match(sprintf($this->urlRegex, $urlRegex), $url, $matches) === false) {
return null;
}
@@ -174,7 +178,7 @@ abstract class Route implements IRoute
/* Only take matched parameters with name */
foreach ((array)$parameters[1] as $name) {
- $values[$name] = (isset($matches[$name]) && $matches[$name] !== '') ? $matches[$name] : null;
+ $values[$name] = (isset($matches[$name]) === true && $matches[$name] !== '') ? $matches[$name] : null;
}
}
diff --git a/src/Pecee/SimpleRouter/Router.php b/src/Pecee/SimpleRouter/Router.php
index be32bcf..2d38a31 100644
--- a/src/Pecee/SimpleRouter/Router.php
+++ b/src/Pecee/SimpleRouter/Router.php
@@ -412,7 +412,7 @@ class Router
if ($methodNotAllowed === true) {
$message = sprintf('Route "%s" or method "%s" not allowed.', $this->request->getUrl()->getPath(), $this->request->getMethod());
- $this->handleException(new HttpException($message, 403));
+ $this->handleException(new NotFoundHttpException($message, 403));
}
if (\count($this->request->getLoadedRoutes()) === 0) {
@@ -457,7 +457,9 @@ class Router
}
if ($this->request->getRewriteUrl() !== $url) {
+
unset($this->processedRoutes[$key]);
+
$this->request->setHasPendingRewrite(false);
$this->fireEvents(EventHandler::EVENT_REWRITE, [
@@ -644,11 +646,7 @@ class Router
}
/* Only merge $_GET when all parameters are null */
- if ($name === null && $parameters === null && $getParams === null) {
- $getParams = $_GET;
- } else {
- $getParams = (array)$getParams;
- }
+ $getParams = ($name === null && $parameters === null && $getParams === null) ? $_GET : (array)$getParams;
/* Return current route if no options has been specified */
if ($name === null && $parameters === null) {
diff --git a/src/Pecee/SimpleRouter/SimpleRouter.php b/src/Pecee/SimpleRouter/SimpleRouter.php
index 5f95ab4..4400118 100644
--- a/src/Pecee/SimpleRouter/SimpleRouter.php
+++ b/src/Pecee/SimpleRouter/SimpleRouter.php
@@ -24,7 +24,6 @@ use Pecee\SimpleRouter\Handlers\IEventHandler;
use Pecee\SimpleRouter\Route\IGroupRoute;
use Pecee\SimpleRouter\Route\IPartialGroupRoute;
use Pecee\SimpleRouter\Route\IRoute;
-use Pecee\SimpleRouter\Route\Route;
use Pecee\SimpleRouter\Route\RouteController;
use Pecee\SimpleRouter\Route\RouteGroup;
use Pecee\SimpleRouter\Route\RoutePartialGroup;
@@ -75,8 +74,7 @@ class SimpleRouter
try {
ob_start();
- static::router()->setDebugEnabled(true);
- static::start();
+ static::router()->setDebugEnabled(true)->start();
$routerOutput = ob_get_contents();
ob_end_clean();
} catch (\Exception $e) {
@@ -187,7 +185,7 @@ class SimpleRouter
*/
public static function get(string $url, $callback, array $settings = null): IRoute
{
- return static::match([Route::REQUEST_TYPE_GET], $url, $callback, $settings);
+ return static::match(['get'], $url, $callback, $settings);
}
/**
@@ -200,7 +198,7 @@ class SimpleRouter
*/
public static function post(string $url, $callback, array $settings = null): IRoute
{
- return static::match([Route::REQUEST_TYPE_POST], $url, $callback, $settings);
+ return static::match(['post'], $url, $callback, $settings);
}
/**
@@ -213,7 +211,7 @@ class SimpleRouter
*/
public static function put(string $url, $callback, array $settings = null): IRoute
{
- return static::match([Route::REQUEST_TYPE_PUT], $url, $callback, $settings);
+ return static::match(['put'], $url, $callback, $settings);
}
/**
@@ -226,7 +224,7 @@ class SimpleRouter
*/
public static function patch(string $url, $callback, array $settings = null): IRoute
{
- return static::match([Route::REQUEST_TYPE_PATCH], $url, $callback, $settings);
+ return static::match(['patch'], $url, $callback, $settings);
}
/**
@@ -239,7 +237,7 @@ class SimpleRouter
*/
public static function options(string $url, $callback, array $settings = null): IRoute
{
- return static::match([Route::REQUEST_TYPE_OPTIONS], $url, $callback, $settings);
+ return static::match(['options'], $url, $callback, $settings);
}
/**