Skip to content

Commit

Permalink
Support getRoute on router
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Mar 17, 2017
1 parent 4bdd907 commit 3c5a9ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Routing/IRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
13 changes: 13 additions & 0 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Router implements IRouter
*/
protected $_routeData;

protected $_pattern = [];

/**
* Set the object you wish to handle routing for
*
Expand Down Expand Up @@ -76,6 +78,7 @@ protected function _processRoutes($url, $routes)
'',
$url
);
$this->_pattern[] = $pattern;
if(is_callable($route))
{
return $this->createRoute($route, $matchedPath);
Expand All @@ -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 == '')
Expand Down

0 comments on commit 3c5a9ff

Please sign in to comment.