Make a finding by \Exedra\Http\Request
@param ServerRequestInterface $request
@return Finding
@throws RouteNotFoundException
508000
public function findByRequest(ServerRequestInterface $request)
    {
        $result = $this->findRouteByRequest($request, trim($request->getUri()->getPath(), '/'));

        if(!$result['route'])
            throw new RouteNotFoundException('Route for request '.$request->getMethod().' '.$request->getUri()->getPath().' does not exist');

        return $this->factory->createFinding($result['route'], $result['parameter'], $request);
    }
1150296
function match(RequestInterface $request)
    {
        $method = $request->getMethod();

        if (strtoupper($method) !== strtoupper($this->getMethod()))
            return false;

        $routeMatch = clone $this;
        return $routeMatch;
    }
374359
public function match(ServerRequestInterface $request)
    {
        $basePathLength = strlen($this->baseUri['path']);

        return RouteCollectionMatcher::matchRouteCollection(
            $this->routeCollection,
            $request,
            $basePathLength,
            []
        ) ?: MatchResult::fromMatchFailure();
    }
697799
private function route(Request $request) : RouteMatch
    {
        foreach ($this->routes as $route) {
            try {
                $match = $route->match($request);
            }
            catch (RoutingException $e) {
                throw new HttpNotFoundException($e->getMessage(), $e);
            }

            if ($match !== null) {
                if ($match instanceof RouteMatch) {
                    return $match;
                }

                throw $this->invalidReturnValue('route', Route::class . ' or NULL', $match);
            }
        }

        throw new HttpNotFoundException('No route matches the request.');
    }
827324
public function listAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $root = $this->getFolderRepository()->findRoot();
        if (null !== $id = $request->query->get('folderId')) {
            if (!$this->activateFolderById($id, $root)) {
                $root->setActive(true);
            }
        } else {
            $root->setActive(true);
        }

        $folders = $this->get('jms_serializer')->serialize(
            array($root),
            'json',
            SerializationContext::create()->setGroups(array('Manager'))
        );

        $response = new Response($folders);
        $response->headers->add(array('Content-Type' => 'application/json'));

        return $response;
    }
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;
    }
568780
protected function doMatch($pathinfo, Request $request = null)
    {
        $matchedRoute = $this->router->match($pathinfo, $request->server->all());
        if ($matchedRoute === false) {
            throw new ResourceNotFoundException();
        }

        $routeParams = $matchedRoute->params;

        // The 'action' key always exists and defaults to the Route Name, so we check accordingly
        if (!isset($routeParams['controller']) && $routeParams['action'] === $matchedRoute->name) {
            throw new \Exception('Matched the route: ' . $matchedRoute->name . ' but unable to locate
            any controller/action params to dispatch');
        }

        // We need _controller, to that symfony ControllerResolver can pick this up
        if (!isset($routeParams['_controller'])) {
            if (isset($routeParams['controller'])) {
                $routeParams['_controller'] = $routeParams['controller'];
            } elseif (isset($routeParams['action'])) {
                $routeParams['_controller'] = $routeParams['action'];
            } else {
                throw new \Exception('Unable to determine the controller from route: ' . $matchedRoute->name);
            }
        }

        $routeParams['_route'] = $matchedRoute->name;

        // If the controller is an Object, and 'action' is defaulted to the route name - we default to __invoke
        if ($routeParams['action'] === $matchedRoute->name) {
            $routeParams['action'] = '__invoke';
        }

        if (false === strpos($routeParams['_controller'], '::') && isset($routeParams['action'])) {
            $routeParams['_controller'] = sprintf('%s::%s',
                $routeParams['_controller'],
                $routeParams['action']
            );
        }

        return $routeParams;
    }
744087
public function modify(ServerRequestInterface $request) : ServerRequestInterface
    {
        /** @var ServerRequestModifierInterface $modifier */
        foreach ($this->collection as $modifier) {
            $request = $modifier->modify($request);
        }

        return $request;
    }
1065021
protected function matchRoute(ServerRequestInterface $request): ?RouteInterface
    {
        foreach ($this->routes as $route) {
            // Matched route will return new route instance with matched parameters
            $matched = $route->match($request);

            if (!empty($matched)) {
                return $matched;
            }
        }

        if (!empty($this->default)) {
            return $this->default->match($request);
        }

        // unable to match any route
        return null;
    }
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'])
            );
        }
    }
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));
        }
    }
1133018
protected function get(ServerRequestInterface $request, bool $next = false): ?MiddlewareInterface
    {
        $index = $next ? ++$this->index : $this->index;

        if (!isset($this->middleware[$index])) {
            return null;
        }

        $middleware = $this->middleware[$index];

        if (\is_array($middleware)) {
            $conditions = $middleware;
            $middleware = \array_pop($conditions);

            if (!Matcher\Factory::matches($conditions, $request)) {
                return $this->get($request, true);
            }
        }

        if (\is_callable($middleware)) {
            return new Middleware\CallableWrapper($middleware);
        }

        if (\is_string($middleware)) {
            if ($this->container === null) {
                throw new \RuntimeException("No valid middleware provided: $middleware");
            }

            $middleware = $this->container->get($middleware);
        }

        if (!$middleware instanceof MiddlewareInterface) {
            throw new \RuntimeException('The middleware must be an instance of MiddlewareInterface');
        }

        return $middleware;
    }
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;
    }
363264
private function generateNotFoundPlainResponse(ServerRequestInterface $request) : ResponseInterface
    {
        $response = ($this->responseFactory)()->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
        $response->getBody()
            ->write(\sprintf(
                "Encountered a 404 Error, %s doesn't exist",
                (string) $request->getUri()
            ));

        return $response;
    }
126186
protected function matchRoute(Request $request, $type)
    {
        $router = $this->container->get('router');

        if ( ! $request->attributes->has('_controller')) {
            try {
                // Attempt to find the route from the request
                $matched = $router->match($request->getPathInfo());
            } catch (ResourceNotFoundException $e) {
                // If no route is found, throw handle a 404 exception
                throw new NotFoundHttpException(sprintf(
                    'No route found for path "%s".',
                    $request->getPath()
                ));
            }
        } else {
            // This will usually be the case if a kernel exception is thrown
            $matched = ['_controller' => $request->attributes->get('_controller')];
        }

        return $matched;
    }
242701
public function notFoundResponse(RequestInterface $request)
    {
        if ($this->missingChain) {
            return $this->missingChain->execute(
                [$this->server, $request],
                $this->middlewares
            );
        }
        return Response::make('<html><head><title>404 Not Found</title></head><body bgcolor="white"><h1>404 Not Found</h1></body></html>', 404);
    }
945854
public function process($serverRequest)
    {
        $match = $this->routeTranslator->match($serverRequest);
        
        if($match !== null) {
            $attributes = $match->attributes();
            $attributes['routeResolverPath'] = $match->resolverPath();

            foreach($attributes as $key => $value) {
                $serverRequest = $serverRequest->withAttribute($key, $value);
            }
        }
        
        return $serverRequest;
    }