From b5e42dbdfb8bf40b903e091efc43ce588605f4ea Mon Sep 17 00:00:00 2001 From: Hannes <31671206+xJuvi@users.noreply.github.com> Date: Sun, 2 Jan 2022 14:42:43 +0100 Subject: [PATCH 1/3] Make current processing rule accessible Adds an constant with the data from the current processing rule to make it globally accessible, f.e. in middleware objects --- src/Pecee/SimpleRouter/Router.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Pecee/SimpleRouter/Router.php b/src/Pecee/SimpleRouter/Router.php index 76721d2..da9e06d 100644 --- a/src/Pecee/SimpleRouter/Router.php +++ b/src/Pecee/SimpleRouter/Router.php @@ -35,6 +35,12 @@ class Router * @var bool */ protected $isProcessingRoute; + + /** + * Defines all data from current processing route. + * @var array + */ + protected $currentProcessingRoute = []; /** * All added routes @@ -371,6 +377,9 @@ class Router foreach ($this->processedRoutes as $key => $route) { $this->debug('Matching route "%s"', get_class($route)); + + /* Add current processing route to constants */ + $this->currentProcessingRoute = $route; /* If the route matches */ if ($route->matchRoute($url, $this->request) === true) { @@ -429,6 +438,9 @@ class Router } } } + + /* Remove the current processing route after handle all possible routes */ + $this->currentProcessingRoute = []; } catch (Exception $e) { $this->handleException($e); @@ -950,4 +962,4 @@ class Router return $this; } -} \ No newline at end of file +} From a1d5f38af7c4fc5ea3411bb5ffef164d4110fe5f Mon Sep 17 00:00:00 2001 From: Hannes <31671206+xJuvi@users.noreply.github.com> Date: Sun, 2 Jan 2022 21:59:39 +0100 Subject: [PATCH 2/3] Add function to fetch currect processing route --- src/Pecee/SimpleRouter/Router.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Pecee/SimpleRouter/Router.php b/src/Pecee/SimpleRouter/Router.php index da9e06d..855f98b 100644 --- a/src/Pecee/SimpleRouter/Router.php +++ b/src/Pecee/SimpleRouter/Router.php @@ -939,6 +939,16 @@ class Router { return $this->debugList; } + + /** + * Get the current processing route details. + * + * @return array + */ + public function getCurrentProcessingRoute(): array + { + return $this->currentProcessingRoute; + } /** * Changes the rendering behavior of the router. From 01bad94af0bc362ae7c37b6e1793c87d55f3ad86 Mon Sep 17 00:00:00 2001 From: Hannes <31671206+xJuvi@users.noreply.github.com> Date: Wed, 2 Feb 2022 15:20:23 +0100 Subject: [PATCH 3/3] Update Router.php --- src/Pecee/SimpleRouter/Router.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Pecee/SimpleRouter/Router.php b/src/Pecee/SimpleRouter/Router.php index 855f98b..509ca2a 100644 --- a/src/Pecee/SimpleRouter/Router.php +++ b/src/Pecee/SimpleRouter/Router.php @@ -38,9 +38,9 @@ class Router /** * Defines all data from current processing route. - * @var array + * @var ILoadableRoute */ - protected $currentProcessingRoute = []; + protected $currentProcessingRoute; /** * All added routes @@ -438,9 +438,6 @@ class Router } } } - - /* Remove the current processing route after handle all possible routes */ - $this->currentProcessingRoute = []; } catch (Exception $e) { $this->handleException($e); @@ -943,9 +940,9 @@ class Router /** * Get the current processing route details. * - * @return array + * @return ILoadableRoute */ - public function getCurrentProcessingRoute(): array + public function getCurrentProcessingRoute(): ILoadableRoute { return $this->currentProcessingRoute; }