From 3c5a9ffde10f19886077323941ed3673fd92b71a Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Fri, 17 Mar 2017 16:25:56 +0000 Subject: [PATCH] Support getRoute on router --- src/Routing/IRouter.php | 7 +++++++ src/Routing/Router.php | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Routing/IRouter.php b/src/Routing/IRouter.php index 018cb28..f92395e 100644 --- a/src/Routing/IRouter.php +++ b/src/Routing/IRouter.php @@ -24,4 +24,11 @@ public function setSubject(IRoutable $subject); * @throws \Exception When no route can be found */ public function process($url); + + /** + * Get the matched route + * + * @return string + */ + public function getRoute(); } diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 2276278..caa04de 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -18,6 +18,8 @@ class Router implements IRouter */ protected $_routeData; + protected $_pattern = []; + /** * Set the object you wish to handle routing for * @@ -76,6 +78,7 @@ protected function _processRoutes($url, $routes) '', $url ); + $this->_pattern[] = $pattern; if(is_callable($route)) { return $this->createRoute($route, $matchedPath); @@ -99,6 +102,16 @@ protected function _processRoutes($url, $routes) return null; } + /** + * Get the matched route + * + * @return string + */ + public function getRoute() + { + return implode('/', array_filter($this->_pattern)); + } + public function matchPattern($url, $pattern) { if($pattern == '' && $url == '')