Match request with provided routes.
Get method and url from provided request and start matching.

@param ServerRequest $request instance of PSR 7 compatible request object

@return mixed
437156
public function matchRequest(ServerRequest $request)
    {
        return $this->getMatchRoute(
            $request->getMethod(),
            $this->getUrl($request)
        );
    }
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;
    }
1287452
public function getMatchingRoute($request)
    {
        // Get matching route
        $this->currentRoute = $route = $this->routes->match($request);

        return $route;
    }
532640
public function find(Request $request)
    {
        $route = $this->getRouteFinder()->find($request, $this->getRoutes());
        $this->setCurrentRoute($route);
        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;
    }
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
        );
    }
1337559
public function dispatch(ServerRequest $request, array $parameters = [])
    {
        $matchedRoute = $this->matcher->matchRequest($request);
        if ($matchedRoute !== false) {
            return $this->dispatcher->dispatchRoute($matchedRoute, $parameters);
        }

        return $this->dispatcher->dispatchNotFound();
    }
12385
public function matchRequest(Request $request, RouteCollectionInterface $routes)
    {
        $path   = $request->getPath();
        $filtered = $this->filterByMethodAndScheme($routes, $request);

        if ($filtered instanceof CachedCollectionInterface && 0 !== count($r = $route->findByStaticPath($path))) {
            $filtered = $r;
        }

        $nomatch = array_diff_key($routes->all(), $filtered->all());

        foreach ($filtered->all() as $name => $route) {
            $rctx = $route->getContext();

            // does it match host?
            if (!$this->matchHost($rctx, $request, $route->getHost())) {
                $nomatch[$name] = $route;
                continue;
            }

            // does it match static path?
            if (0 !== strpos($path, $rctx->getStaticPath())) {
                continue;
            }

            // does it match pattern described on the route?
            if ((bool)preg_match_all($rctx->getRegex(), $path, $matches)) {
                $vars    = $this->getMatchedVars($route, $matches);
                $handler = $route->getHandler();

                return new MatchContext(self::MATCH, $name, $request, $handler, $vars);
            }

            $nomatch[$name] = $route;
        }

        return new MatchContext($this->getMatchFailureReason($nomatch, $request), null, $request, null);
    }
91397
protected function getPsrRequestViaBearerToken($request)
    {
        // First, we will convert the Symfony request to a PSR-7 implementation which will
        // be compatible with the base OAuth2 library. The Symfony bridge can perform a
        // conversion for us to a Zend Diactoros implementation of the PSR-7 request.
        $psr = (new DiactorosFactory)->createRequest($request);

        try {
            return $this->server->validateAuthenticatedRequest($psr);
        } catch (OAuthServerException $e) {
            $request->headers->set('Authorization', '', true);

            Container::getInstance()->make(
                ExceptionHandler::class
            )->report($e);
        }
    }
550614
public function match($request, $partial = null)
    {
        $path        = trim($request->getPathInfo(), self::URI_DELIMITER);
        $subPath     = $path;
        $values      = array();
        $numRoutes   = count($this->_routes);
        $matchedPath = null;

        foreach ($this->_routes as $key => $route) {
            if ($key > 0
                && $matchedPath !== null
                && $subPath !== ''
                && $subPath !== false
            ) {
                $separator = substr($subPath, 0, strlen($this->_separators[$key]));

                if ($separator !== $this->_separators[$key]) {
                    return false;
                }

                $subPath = substr($subPath, strlen($separator));
            }

            // TODO: Should be an interface method. Hack for 1.0 BC
            if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
                $match = $subPath;
            } else {
                $request->setPathInfo($subPath);
                $match = $request;
            }

            $res = $route->match($match, true, ($key == $numRoutes - 1));
            if ($res === false) {
//BEGIN FIX
                $request->setPathInfo($path);
//END FIX
                return false;
            }

            $matchedPath = $route->getMatchedPath();

            if ($matchedPath !== null) {
                $subPath     = substr($subPath, strlen($matchedPath));
                $separator   = substr($subPath, 0, strlen($this->_separators[$key]));
            }

            $values = $res + $values;
        }

        $request->setPathInfo($path);

        if ($subPath !== '' && $subPath !== false) {
            return false;
        }

        return $values;
    }
1161161
protected function getPoint(ServerRequestInterface $request): callable
    {
        $controller = $this->getController($request);
        $action = $this->getAction($request) ?? 'index';
        $this->checkAction($controller, $action);

        return [$controller, $action];
    }
671580
protected function matchRoutes(RequestInterface $request, int $pathOffset): ?RouteMatchInterface
    {
        $notAllowed = null;
        $routes = $this->getRoutes();
        foreach ($routes as $route) {
            try {
                $match = $route->match($request, $pathOffset);
                if ($match instanceof RouteMatchInterface) {
                    return $match;
                }
            } catch (MethodNotAllowed $exception) {
                if ($notAllowed instanceof MethodNotAllowed) {
                    $notAllowed->addAllowedMethods($exception->getAllowedMethods());
                } else {
                    $notAllowed = $exception;
                }
            }
        }

        if ($notAllowed instanceof MethodNotAllowed) {
            throw $notAllowed;
        }

        return null;
    }
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);
    }
702729
protected function dispatchRequestToAuthorizationServer(ServerRequest $request)
    {
        return json_decode($this->server->respondToAccessTokenRequest(
            $request, new Response
        )->getBody()->__toString(), true);
    }
314338
public function getRouteForRequest(Request $request)
    {
        $routes = $this->collection->get($request->getMethod());

        return $this->check($routes, $request);
    }
1068465
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $body = $request->getParsedBody();

        $method = strtoupper($body[self::METHOD_INPUT_KEY] ?? $request->getMethod());

        $request = $request->withMethod($method);

        $this->match = $this->adapter->match($request);

        return $this->match->handle($request);
    }
319265
public function route($request = NULL)
    {
        $matchedResource = NULL;
        if (!$request) {
            $request = new Request();
        }
        foreach ($this->resources as $className => $resourceMetadata) {
            foreach ($resourceMetadata->getUri() as $index => $uri) {
                $uriRegex = '|^'.$uri.'$|';
                if (
                    ($matchedResource == NULL || $matchedResource[0]->getPriority() < $resourceMetadata->getPriority())
                &&
                    preg_match($uriRegex, $request->getUri(), $params)
                ) {
                    array_shift($params);
                    $uriParams = $resourceMetadata->getUriParams($index);
                    if ($uriParams) { // has params within URI
                        foreach ($uriParams as $key => $name) {
                            $params[$name] = $params[$key];
                        }
                    }
                    $matchedResource = array($resourceMetadata, $params);
                }
            }
        }
        if ($matchedResource) {
            $request->setParams($matchedResource[1]);

            return $matchedResource[0];
        } else {
            throw new NotFoundException(sprintf('Resource matching URI "%s" not found', $request->uri));
        }
    }