From 341d7837a1afe29a2a950440e239af4ad5550f0f Mon Sep 17 00:00:00 2001 From: KJ Date: Fri, 8 Sep 2023 22:42:50 -0400 Subject: [PATCH] Add Router::reconfigure method. --- src/Libs/Router.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Libs/Router.php b/src/Libs/Router.php index 5022ca5..5cdb7c0 100644 --- a/src/Libs/Router.php +++ b/src/Libs/Router.php @@ -163,9 +163,32 @@ class Router { return (object) ''; } + /** + * Reconfigura el callback final de la última ruta. + * + * @param callable $callback + * + * @return static + */ + public static function reconfigure(callable $callback): static { + if (empty(static::$last)) + return new static(); + + $method = static::$last[0]; + $index = static::$last[1]; + + static::$$method[$index]['callback'][0] = $callback; + + return new static(); + } + /** * Configura calquier método para todas las rutas. * + * En caso de no recibir un callback, busca la ruta actual + * solo configura la ruta como la última configurada + * siempre y cuando la misma haya sido configurada previamente. + * * @param string $method * Método http. * @param string $path