From 7e7ec68fd70f45494365c8669ffd12e5ca3ccea1 Mon Sep 17 00:00:00 2001 From: kj Date: Thu, 16 Oct 2025 12:04:05 -0300 Subject: [PATCH] refactor(router): Use Neuron object for route parameters --- src/Libs/Request.php | 2 +- src/Libs/Router.php | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Libs/Request.php b/src/Libs/Request.php index 75fea8e..7ffbe6a 100644 --- a/src/Libs/Request.php +++ b/src/Libs/Request.php @@ -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"]) : ''; diff --git a/src/Libs/Router.php b/src/Libs/Router.php index 3793a6d..26a7550 100644 --- a/src/Libs/Router.php +++ b/src/Libs/Router.php @@ -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]); } }