Matches the request to a route.

@param ServerRequestInterface $request
@throws HttpException
@return RouterMatch
161085
private function matchRoute(ServerRequestInterface $request) : RouterMatch
    {
        $this->eventDispatcher->dispatch(new EventBeforeAppMatchingRoute($request));
        try {
            $routerMatch = $this->router->match($request);
        } catch (\Throwable $e) {
            $statusCode = 404;
            $message = "$statusCode: Router could not match request path {$request->getUri()->getPath()}";
            throw new HttpException($statusCode, $message, null, $e);
        }
        $this->eventDispatcher->dispatch(new EventAfterAppMatchingRoute($request, $routerMatch));
        return $routerMatch;
    }
165824
public function match(Request $request)
    {
        try {
            return parent::match($request);
        } catch (NotFoundHttpException $e) {
            $route = $this->findMatchingWordpressPost();

            if ( ! is_null($route)) {
                return $route->bind($request);
            }

            throw $e;
        }
    }
451253
public function match(Request $request)
    {
        $routes = $this->get($request->getMethod());

        // First, we will see if we can find a matching route for this current request
        // method. If we can, great, we can just return it so that it can be called
        // by the consumer. Otherwise we will check for routes with another verb.

        if (! is_null($route = $this->fastCheck($routes, $request))) {
            // A route was found in the fast way.
        } else {
            $route = $this->check($routes, $request);
        }

        if (! is_null($route)) {
            return $route->bind($request);
        }

        // If no route was found, we will check if a matching route is specified on
        // another HTTP verb. If it is we will need to throw a MethodNotAllowed and
        // inform the user agent of which HTTP verb it should use for this route.

        $others = $this->checkForAlternateVerbs($request);

        if (! empty($others)) {
            return $this->getOtherMethodsRoute($request, $others);
        }

        throw new NotFoundHttpException;
    }
818123
private function chooseHttpClient(RequestInterface $request)
    {
        foreach ($this->clients as $client) {
            if ($client['matcher']->matches($request)) {
                return $client['client'];
            }
        }

        throw new HttpClientNoMatchException('No client found for the specified request', $request);
    }
461169
public function matchRequest(Request $request)
    {
        try {
            $parameters = parent::matchRequest($request);
            $this->matchedRouteRequest = $request;
            return $parameters;
        } catch (\Exception $e) {
            throw $e;
        }


    }
894893
public function matchRequest(RequestInterface $request)
    {
        if (!isset($this->options['hostPattern'])) {
            throw new InvalidRequestPatternException('Missing option "hostPattern" in the Host request pattern configuration', 1446224510);
        }
        if (!$request instanceof ActionRequest) {
            return false;
        }
        $hostPattern = str_replace('\\*', '.*', preg_quote($this->options['hostPattern'], '/'));
        return preg_match('/^' . $hostPattern . '$/', $request->getHttpRequest()->getUri()->getHost()) === 1;
    }
799728
private function match($request)
    {
        $route = $this->router->match(
            $request->getUri()->getPath(),
            $request->getMethod()
        );
        if (!$route) {
            // not matched. dispatch the next middleware.
            return $this->next ? $this->next->__invoke($request) : null;
        }
        return $this->dispatch($request, $route);
    }
292091
public function dispatch(ServerRequestInterface $request)
    {
        if ($this->routeMatched) {
            if (!is_subclass_of($this->actionNamespace, 'App\Action\AppAction')) {
                throw new BaseException(
                    sprintf('Action "%s" does not extend App\Action\AppAction', $this->actionNamespace)
                );
            }

            $actionInstance = new $this->actionNamespace();

            $beforeDispatchEvent = $this->dispatchEvent(
                self::EVENT_BEFORE_DISPATCH,
                $this,
                ['request' => $request, 'action' => $actionInstance]
            );

            if ($beforeDispatchEvent->getResult() instanceof Response) {
                return $beforeDispatchEvent->getResult();
            }

            $response = call_user_func_array([$actionInstance, 'invoker'], $this->params);
            $this->dispatchEvent(self::EVENT_AFTER_DISPATCH, $this, ['request' => $request, 'response' => $response]);

            return $response;
        } else {
            throw new NotFoundException(
                sprintf('Route "%s" does not found', $request->getServerParams()['REQUEST_URI'])
            );
        }
    }
674218
public function match(HttpServletRequestInterface $servletRequest)
    {
        return fnmatch($this->getUrlPattern(), $servletRequest->getServletPath() . $servletRequest->getPathInfo());
    }
37003
function match(RequestInterface $request)
    {
        if ($preReq = $this->getPreparator()) {
            $request = $preReq->withRequestOnMatch($request);

            if (! $request instanceof RequestInterface )
                throw new \RuntimeException(sprintf(
                    'Missing RequestInterface While Preparing Request Object Through (%s).'
                    , \Poirot\Std\flatten($preReq)
                ));
        }


        ## match against connected routers if exists
        if (empty($this->routesAdd))
            return false;

        # build queue list for routers to match:

        # match routes:
        $routeMatch = false;
        foreach($this->_priorityQueue() as $route) {
            /** @var iRoute $r */
            $r = $route;
            if ($routeMatch = $r->match($request)) break;
        }

        ## if route match merge stack default params with match route
        /** @var iRoute $routeMatch */
        if ($routeMatch) {
            # $routeMatch = clone $routeMatch; // this can be skipped because use of match on each route
            \Poirot\Router\mergeParamsIntoRouter($routeMatch, $this->params());
        }

        return $routeMatch;
    }
642624
public function getRoute(ServerRequestInterface $request)
    {
        $url = $request->getUri();
        $route = $this->findRoute($url, $request->getMethod());
        
        if ($route) {
            $route = $this->bind($route, $request, $this->splitUrl($url->getPath()));
        }
        
        return $route;
    }
520023
public function match(Request $request, $route = false)
    {
        if (count($this->_childs)) {
            $route = $this->_match($request, $route);
        }

        if (!$route) {
            $route = $this->_default($request)->merge($route);
        }


        if (!$route) {
            throw new RuntimeException("Missing route...");
        }

        return $route;
    }
81361
protected function _checkUrl(ServerRequestInterface $request)
    {
        return $this->_getUrlChecker()->check(
            $request,
            $this->getConfig('loginUrl'),
            (array)$this->getConfig('urlChecker')
        );
    }
1293086
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if (!isset($this->middlewaresInPipe[$this->currentMiddlewareInPipeIndex])) {
            return $this->generate404($request);
        }

        $middleware = $this->getMiddlewareInPipe();
        if (\is_callable($middleware)) {
            return \call_user_func_array($middleware, [$request, [$this, 'handle']]);
        } elseif ($middleware instanceof MiddlewareInterface) {
            return $middleware->process($request, $this);
        } elseif (\is_string($middleware)) {
            $middlewareInstance = (new $middleware());
            if (\method_exists($middlewareInstance, 'process')) {
                return $middlewareInstance->process($request, $this);
            }
        } elseif ($middleware instanceof self) {
            if ($middleware->findRouteRequest($request)) {
                return $middleware->dispatch($request);
            }

            return $this->handle($request);
        }
        throw new RouterException(\sprintf('Middleware is invalid: %s', \gettype($middleware)));
    }
845434
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return $this->dispatchRoute($this->resolve($request), $request);
    }
908289
public function find(Request $request, array $routes)
    {
        foreach ($routes as $route) {

            if(!$this->matchMethod($request, $route)){
                continue;
            }

            if(!$this->matchContentType($request, $route)){
                continue;
            }

            if(!$this->matchFilters($route)){
                continue;
            }

            $routeMatches = $this->matchPattern($request, $route);
            if ($routeMatches) {
                $route->setMatches($routeMatches);
                return $route;
            }
        }
        throw new RouteException(
            sprintf('No route found for uri "%s"', $request->getRequestUri()),
            $request,
            $routes
        );
    }
19216
public function match(RequestInterface $request)
    {
        return (
            $this->matchSchema($request->schema()) &&
            $this->matchMethods($request->method()) &&
            $this->matchHost($request->host()) &&
            $this->matchPath($request->path())
        );
    }