refactor(router): Use Neuron object for route parameters
This commit is contained in:
@@ -38,7 +38,7 @@ class Request extends Neuron
|
||||
$this->put = new Neuron();
|
||||
$this->patch = new Neuron();
|
||||
$this->delete = new Neuron();
|
||||
$this->params = new Neuron(Router::$currentParams);
|
||||
$this->params = Router::$params ?? new Neuron();
|
||||
$this->body = file_get_contents("php://input");
|
||||
|
||||
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
|
||||
|
||||
@@ -15,28 +15,28 @@ namespace Libs;
|
||||
*/
|
||||
class Router
|
||||
{
|
||||
private static $get = [];
|
||||
private static $post = [];
|
||||
private static $put = [];
|
||||
private static $patch = [];
|
||||
private static $delete = [];
|
||||
private static array $get = [];
|
||||
private static array $post = [];
|
||||
private static array $put = [];
|
||||
private static array $patch = [];
|
||||
private static array $delete = [];
|
||||
/**
|
||||
* Stores the method and index of the last configured route, e.g., ['get', 0].
|
||||
* Used for chaining methods like middleware() or reconfigure().
|
||||
*
|
||||
* @var array|null
|
||||
* @var array $last
|
||||
*/
|
||||
private static $last;
|
||||
private static array $last;
|
||||
/**
|
||||
* Stores the parameters extracted from the current matching route.
|
||||
*
|
||||
* @var array
|
||||
* @var Neuron $params
|
||||
*/
|
||||
public static $currentParams = [];
|
||||
public static Neuron $params;
|
||||
/**
|
||||
* The callback function to be executed when no route matches.
|
||||
*
|
||||
* @var callable|string
|
||||
* @var callable $notFoundCallback
|
||||
*/
|
||||
public static $notFoundCallback = 'Libs\Router::defaultNotFound';
|
||||
|
||||
@@ -345,9 +345,10 @@ class Router
|
||||
|
||||
// Checking and storing the variable parameters of the route
|
||||
if (isset($matches[1])) {
|
||||
static::$params = new Neuron();
|
||||
foreach ($matches as $index => $match) {
|
||||
$paramName = $router['paramNames'][$index - 1];
|
||||
static::$currentParams[$paramName] = urldecode($match[0]);
|
||||
static::$params->{$paramName} = urldecode($match[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user