mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 20:22:12 +00:00
Bugfixes
This commit is contained in:
@@ -37,6 +37,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
|||||||
$middleware = $this->getMiddlewares()[$i];
|
$middleware = $this->getMiddlewares()[$i];
|
||||||
|
|
||||||
$middleware = $this->loadClass($middleware);
|
$middleware = $this->loadClass($middleware);
|
||||||
|
|
||||||
if (!($middleware instanceof IMiddleware)) {
|
if (!($middleware instanceof IMiddleware)) {
|
||||||
throw new HttpException($middleware . ' must be instance of Middleware');
|
throw new HttpException($middleware . ' must be instance of Middleware');
|
||||||
}
|
}
|
||||||
@@ -60,7 +61,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
|||||||
|
|
||||||
/* Remove global match */
|
/* Remove global match */
|
||||||
if (count($parameters) > 1) {
|
if (count($parameters) > 1) {
|
||||||
$this->setParameters(array_slice($parameters, 1));
|
$this->parameters = array_slice($parameters, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ abstract class Route implements IRoute
|
|||||||
|
|
||||||
protected function loadClass($name)
|
protected function loadClass($name)
|
||||||
{
|
{
|
||||||
if (!class_exists($name)) {
|
if (class_exists($name) === false) {
|
||||||
throw new NotFoundHttpException(sprintf('Class %s does not exist', $name), 404);
|
throw new NotFoundHttpException(sprintf('Class %s does not exist', $name), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,7 +528,6 @@ abstract class Route implements IRoute
|
|||||||
* If this is the first time setting parameters we store them so we
|
* If this is the first time setting parameters we store them so we
|
||||||
* later can organize the array, in case somebody tried to sort the array.
|
* later can organize the array, in case somebody tried to sort the array.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(count($parameters) > 0 && count($this->originalParameters) === 0) {
|
if(count($parameters) > 0 && count($this->originalParameters) === 0) {
|
||||||
$this->originalParameters = $parameters;
|
$this->originalParameters = $parameters;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
|
|||||||
//array_shift($path);
|
//array_shift($path);
|
||||||
//$this->parameters = $path;
|
//$this->parameters = $path;
|
||||||
|
|
||||||
$this->setParameters(array_slice($path, 1));
|
$this->parameters = array_slice($path, 1);
|
||||||
|
|
||||||
// Set callback
|
// Set callback
|
||||||
$this->setCallback($this->controller . '@' . $this->method);
|
$this->setCallback($this->controller . '@' . $this->method);
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ class RouteGroup extends Route implements IGroupRoute
|
|||||||
|
|
||||||
if ($parameters !== null && count($parameters) > 0) {
|
if ($parameters !== null && count($parameters) > 0) {
|
||||||
|
|
||||||
$this->setParameters($parameters);
|
$this->parameters = $parameters;
|
||||||
//$this->parameters = array_merge($this->parameters, $parameters);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,19 +82,19 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
|||||||
$url = rtrim($url, '/') . '/';
|
$url = rtrim($url, '/') . '/';
|
||||||
|
|
||||||
/* Match global regular-expression for route */
|
/* Match global regular-expression for route */
|
||||||
if($this->matchRegex($request, $url) === true) {
|
$domainMatch = $this->matchRegex($request, $url);
|
||||||
return true;
|
if($domainMatch !== null) {
|
||||||
|
return $domainMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
$route = rtrim($this->url, '/') . '/{id?}/{action?}';
|
$route = rtrim($this->url, '/') . '/{id?}/{action?}';
|
||||||
|
|
||||||
$parameters = $this->parseParameters($route, $url);
|
$parameters = $this->parseParameters($route, $url);
|
||||||
|
|
||||||
if ($parameters === null) {
|
if ($parameters === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setParameters((array)$parameters);
|
$this->parameters = (array)$parameters;
|
||||||
|
|
||||||
$action = isset($this->parameters['action']) ? $this->parameters['action'] : null;
|
$action = isset($this->parameters['action']) ? $this->parameters['action'] : null;
|
||||||
unset($this->parameters['action']);
|
unset($this->parameters['action']);
|
||||||
@@ -107,7 +107,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
if (isset($this->parameters['id']) && in_array($method, [ static::REQUEST_TYPE_PATCH, static::REQUEST_TYPE_PUT ])) {
|
if (isset($this->parameters['id']) && in_array($method, [ static::REQUEST_TYPE_PATCH, static::REQUEST_TYPE_PUT ], false)) {
|
||||||
return $this->call($this->methodNames['update']);
|
return $this->call($this->methodNames['update']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ class RouteUrl extends LoadableRoute
|
|||||||
$url = rtrim($url, '/') . '/';
|
$url = rtrim($url, '/') . '/';
|
||||||
|
|
||||||
/* Match global regular-expression for route */
|
/* Match global regular-expression for route */
|
||||||
if($this->matchRegex($request, $url) === true) {
|
$domainMatch = $this->matchRegex($request, $url);
|
||||||
return true;
|
if($domainMatch !== null) {
|
||||||
|
return $domainMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make regular expression based on route */
|
/* Make regular expression based on route */
|
||||||
|
|||||||
Reference in New Issue
Block a user