CapMousse\ReactRestify\Routing\Router::matchRoutes PHP Method

matchRoutes() private method

Try to match the current uri with all routes
private matchRoutes ( Request $request, CapMousse\ReactRestify\Http\Response $response, $next ) : Void
$request CapMousse\ReactRestify\Http\Request
$response CapMousse\ReactRestify\Http\Response
return Void
    private function matchRoutes(Request $request, Response $response, $next)
    {
        $badMethod = false;
        foreach ($this->routes as $route) {
            if (!$route->isParsed()) {
                $route->parse();
            }
            if (preg_match('#' . $route->parsed . '$#', $request->httpRequest->getPath(), $array)) {
                if ($route->method != strtoupper($request->httpRequest->getMethod())) {
                    $badMethod = true;
                    continue;
                }
                $methodArgs = array();
                foreach ($array as $name => $value) {
                    if (!is_int($name)) {
                        $methodArgs[$name] = $value;
                    }
                }
                if (count($methodArgs) > 0) {
                    $request->setData($methodArgs);
                }
                $route->run($request, $response, $next);
                return;
            }
        }
        if ($badMethod) {
            $this->emit('MethodNotAllowed', array($request, $response, $next));
            return;
        }
        $this->emit('NotFound', array($request, $response, $next));
    }