From a2c4619b2111dcc08e3643e3ffc63160ea877713 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 9 Aug 2016 11:41:28 +0200 Subject: [PATCH] Allow string routing instead of only requests --- Router/Router.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Router/Router.php b/Router/Router.php index 064a9cd1c..ed529f03d 100644 --- a/Router/Router.php +++ b/Router/Router.php @@ -102,15 +102,26 @@ class Router * * @return string[] * + * @throws + * * @since 1.0.0 * @author Dennis Eichhorn */ - public function route(RequestAbstract $request) : array + public function route($request, string $verb = RouteVerb::GET) : array { + if($request instanceof RequestAbstract) { + $uri = $request->getUri(); + $verb = $request->getRouteVerb(); + } elseif(is_string($request)) { + $uri = $request; + } else { + throw new \Exception(); + } + $bound = []; foreach ($this->routes as $route => $destination) { foreach ($destination as $d) { - if ($this->match($route, $d['verb'], $request->getUri(), $request->getRouteVerb())) { + if ($this->match($route, $d['verb'], $uri, $verb)) { $bound[] = ['dest' => $d['dest']]; } }