Skip to content

Commit

Permalink
Merge pull request #5 from ZherebcovSergey/patch-4
Browse files Browse the repository at this point in the history
Update Router.php
  • Loading branch information
oleksandr-diudiun authored Sep 25, 2018
2 parents 072090a + 6ba4419 commit c0f71cc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function loadRoutes(array $routes) {
$this->routes = $routes;
}

public function matchRoute(string $rawUrl, string $method): void{
public function matchRoute(string $rawUrl, string $method): array{
$url = parse_url($rawUrl);
if (!isset($url['path']) || is_string($url['path']) === false) {
throw new RoutingException(_("Router can't parse request."), 400);
Expand All @@ -34,7 +34,7 @@ public function matchRoute(string $rawUrl, string $method): void{
if (!is_array($this->routes)) {
throw new RoutingException(_("Can't find any routes rules."), 501);
}

$params = [];
foreach ($this->routes as $regExpString => $route) {
$routes = 0;
$result = preg_match("/^" . str_replace("/", "\/", $regExpString) . "$/u", $url['path'], $matches);
Expand All @@ -50,10 +50,10 @@ public function matchRoute(string $rawUrl, string $method): void{
$paramsCount = count($route[$method]) - 2;
if ($paramsCount > 0) {
for ($i = 0; $i < $paramsCount; $i++) {
$this->params[$route[$method][$i + 2]] = $matches[$i + 1];
$params[$route[$method][$i + 2]] = $matches[$i + 1];
}
} else {
$this->params = array();
$params = array();
}

$routes++;
Expand All @@ -69,6 +69,7 @@ public function matchRoute(string $rawUrl, string $method): void{
if ($routes > 1) {
throw new RoutingException(_("Conflict. Multiple routes found."), 501);
}
return $params;
}

public function getParams(): ? array{
Expand Down

0 comments on commit c0f71cc

Please sign in to comment.