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] 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 +}