mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
Cleanup
This commit is contained in:
@@ -94,8 +94,7 @@ class Input
|
||||
|
||||
$path = $original[$property];
|
||||
|
||||
$tmp = array_values($index);
|
||||
foreach ($tmp as $i) {
|
||||
foreach (array_values($index) as $i) {
|
||||
$path = $path[$i];
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
}
|
||||
}
|
||||
|
||||
public function matchRegex(Request $request, $url) {
|
||||
public function matchRegex(Request $request, $url)
|
||||
{
|
||||
|
||||
/* Match on custom defined regular expression */
|
||||
|
||||
|
||||
@@ -102,11 +102,11 @@ abstract class Route implements IRoute
|
||||
|
||||
$urlParts = preg_split('/\{[^}]+\}/is', rtrim($route, '/'));
|
||||
|
||||
foreach($urlParts as $key => $t) {
|
||||
foreach ($urlParts as $key => $t) {
|
||||
|
||||
$regex = '';
|
||||
|
||||
if($key < (count($parameters[1]))) {
|
||||
if ($key < (count($parameters[1]))) {
|
||||
|
||||
$name = $parameters[1][$key];
|
||||
$regex = isset($this->where[$name]) ? $this->where[$name] : $parameterRegex;
|
||||
@@ -123,12 +123,12 @@ abstract class Route implements IRoute
|
||||
$urlRegex = preg_quote($route, '/');
|
||||
}
|
||||
|
||||
if(preg_match('/^' . $urlRegex . '(\/?)$/is', $url, $matches) > 0) {
|
||||
if (preg_match('/^' . $urlRegex . '(\/?)$/is', $url, $matches) > 0) {
|
||||
|
||||
$values = [];
|
||||
|
||||
/* Only take matched parameters with name */
|
||||
foreach($parameters[1] as $name) {
|
||||
foreach ($parameters[1] as $name) {
|
||||
$values[$name] = $matches[$name];
|
||||
}
|
||||
|
||||
@@ -441,9 +441,9 @@ abstract class Route implements IRoute
|
||||
public function getParameters()
|
||||
{
|
||||
/* Sort the parameters after the user-defined param order, if any */
|
||||
$parameters = array();
|
||||
$parameters = [];
|
||||
|
||||
if(count($this->originalParameters) > 0) {
|
||||
if (count($this->originalParameters) > 0) {
|
||||
$parameters = $this->originalParameters;
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ abstract class Route implements IRoute
|
||||
* 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.
|
||||
*/
|
||||
if(count($parameters) > 0 && count($this->originalParameters) === 0) {
|
||||
if (count($parameters) > 0 && count($this->originalParameters) === 0) {
|
||||
$this->originalParameters = $parameters;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
|
||||
if ($method !== null) {
|
||||
|
||||
/* Remove requestType from method-name, if it exists */
|
||||
foreach(static::$requestTypes as $requestType) {
|
||||
foreach (static::$requestTypes as $requestType) {
|
||||
|
||||
if (stripos($method, $requestType) === 0) {
|
||||
$method = substr($method, strlen($requestType));
|
||||
@@ -89,7 +89,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
|
||||
$url = rtrim($url, '/') . '/';
|
||||
|
||||
/* Match global regular-expression for route */
|
||||
if($this->matchRegex($request, $url) === true) {
|
||||
if ($this->matchRegex($request, $url) === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,14 @@ class RouteGroup extends Route implements IGroupRoute
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach($this->domains as $domain) {
|
||||
foreach ($this->domains as $domain) {
|
||||
|
||||
$parameters = $this->parseParameters($domain, $request->getHost(), '.*');
|
||||
|
||||
if ($parameters !== null && count($parameters) > 0) {
|
||||
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
||||
|
||||
/* Match global regular-expression for route */
|
||||
$domainMatch = $this->matchRegex($request, $url);
|
||||
if($domainMatch !== null) {
|
||||
if ($domainMatch !== null) {
|
||||
return $domainMatch;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
||||
}
|
||||
|
||||
// Update
|
||||
if (isset($this->parameters['id']) && in_array($method, [ static::REQUEST_TYPE_PATCH, static::REQUEST_TYPE_PUT ], false)) {
|
||||
if (isset($this->parameters['id']) && in_array($method, [static::REQUEST_TYPE_PATCH, static::REQUEST_TYPE_PUT], false)) {
|
||||
return $this->call($this->methodNames['update']);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@ class RouteUrl extends LoadableRoute
|
||||
|
||||
/* Match global regular-expression for route */
|
||||
$domainMatch = $this->matchRegex($request, $url);
|
||||
if($domainMatch !== null) {
|
||||
if ($domainMatch !== null) {
|
||||
return $domainMatch;
|
||||
}
|
||||
|
||||
/* Make regular expression based on route */
|
||||
$parameters = $this->parseParameters($this->url, $url);
|
||||
if($parameters === null) {
|
||||
if ($parameters === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user