Skip to content

Commit c481f06

Browse files
committed
new method getMatchedRoute was added
1 parent 4136990 commit c481f06

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Router.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class Router implements MiddlewareInterface, RequestHandlerInterface, RequestMet
8383
*/
8484
private $middlewares = [];
8585

86+
/**
87+
* The router's matched route
88+
*
89+
* @var RouteInterface|null
90+
*/
91+
private $matchedRoute = null;
92+
8693
/**
8794
* Gets the router host table
8895
*
@@ -115,6 +122,16 @@ public function getMiddlewares() : array
115122
return array_values($this->middlewares);
116123
}
117124

125+
/**
126+
* Gets the router's matched route
127+
*
128+
* @return RouteInterface|null
129+
*/
130+
public function getMatchedRoute() : ?RouteInterface
131+
{
132+
return $this->matchedRoute;
133+
}
134+
118135
/**
119136
* Adds the given patterns to the router
120137
*
@@ -355,7 +372,9 @@ public function run(ServerRequestInterface $request) : ResponseInterface
355372
{
356373
// lazy resolving of the given request...
357374
$routing = new CallableRequestHandler(function (ServerRequestInterface $request) : ResponseInterface {
358-
return $this->match($request)->handle($request);
375+
$route = $this->match($request);
376+
$this->matchedRoute = $route;
377+
return $route->handle($request);
359378
});
360379

361380
$middlewares = $this->getMiddlewares();
@@ -375,6 +394,7 @@ public function run(ServerRequestInterface $request) : ResponseInterface
375394
public function handle(ServerRequestInterface $request) : ResponseInterface
376395
{
377396
$route = $this->match($request);
397+
$this->matchedRoute = $route;
378398

379399
$middlewares = $this->getMiddlewares();
380400
if (empty($middlewares)) {

0 commit comments

Comments
 (0)