mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
[FEATURE] php8 compatibility.
- Fixed possible error causing parameters not to be set properly when using partialGroup. - Removed unused import reference. - Added unit-tests.
This commit is contained in:
@@ -31,7 +31,7 @@ class ClassLoader implements IClassLoader
|
||||
*/
|
||||
public function loadClosure(Callable $closure, array $parameters)
|
||||
{
|
||||
return \call_user_func_array($closure, $parameters);
|
||||
return \call_user_func_array($closure, array_values($parameters));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Pecee\SimpleRouter\Route;
|
||||
|
||||
use Pecee\Http\Middleware\IMiddleware;
|
||||
use Pecee\Http\Request;
|
||||
use Pecee\SimpleRouter\Exceptions\ClassNotFoundHttpException;
|
||||
use Pecee\SimpleRouter\Exceptions\NotFoundHttpException;
|
||||
@@ -153,12 +152,22 @@ abstract class Route implements IRoute
|
||||
|
||||
if (isset($parameters[1]) === true) {
|
||||
|
||||
$groupParameters = $this->getGroup() !== null ? $this->getGroup()->getParameters() : [];
|
||||
|
||||
/* Only take matched parameters with name */
|
||||
foreach ((array)$parameters[1] as $name) {
|
||||
|
||||
// Skip parent parameters
|
||||
if(isset($groupParameters[$name]) === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$values[$name] = (isset($matches[$name]) === true && $matches[$name] !== '') ? $matches[$name] : null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->originalParameters = $values;
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
@@ -477,14 +486,6 @@ abstract class Route implements IRoute
|
||||
*/
|
||||
public function setParameters(array $parameters): 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) {
|
||||
$this->originalParameters = $parameters;
|
||||
}
|
||||
|
||||
$this->parameters = array_merge($this->parameters, $parameters);
|
||||
|
||||
return $this;
|
||||
|
||||
Reference in New Issue
Block a user