Create route finding
@param Route|null $route
@param array $parameters
@param ServerRequestInterface $request
@return \Exedra\Routing\Finding
545346
public function createFinding(Route $route = null, array $parameters = null, ServerRequestInterface $request = null)
	{
		return $this->create('finding', array($route, $parameters, $request));
	}
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;
    }
414485
public static function route(Http\Request $request)
    {
        $path = $request->REQUEST_URI;
        $key = $request->getMethod().'@'.$path;
        $keyAny = 'ANY@'.$path;

        $matchedRoute = null;
        $matchedScore = 0;

        if (isset(self::$routes[$key])) {
            $matchedRoute = self::$routes[$key];
        } elseif (isset(self::$routes[$keyAny])) {
            $matchedRoute = self::$routes[$keyAny];
        } else {
            foreach (self::$routes as $key2 => $route) {
                if ($route->getMethod() != 'ANY' && $route->getMethod() != $request->getMethod()) {
                    continue;
                }

                $score = $route->getScore($path, $request->getMethod());
                if ($score > $matchedScore) {
                    $matchedRoute = $route;
                    $matchedScore = $score;
                }
            }
        }

        if ($matchedRoute) {
            $matchedRoute->setUrl($path);
        } elseif (self::$_404route) {
            $matchedRoute = self::$_404route;
        } else {
            throw new Exceptions\RouteException('Route not found');
        }
        return $matchedRoute;
    }
252682
protected function redirectTo($route, array $parameters = [])
    {
        $url = $this->url->toRoute($route, $parameters);

        return $this->makeRedirect($url);
    }
152817
private function buildRequest($client, $route, $params)
    {
        list($resource, $method) = $this->explodeRoute($route);

        if (array_key_exists('parameters', $params)) {
            $parameters = $params['parameters'];
            unset($params['parameters']);

            return call_user_func_array(
                [ $client->setAsync()->{$resource}, $method ],
                array_merge($parameters, [$params])
            );
        }

        return $client->setAsync()->{$resource}->{$method}($params);
    }
675414
public function dispatchRoute(Parsed $route, array $parameters = [])
    {
        $handler = $route->getHandler();
        if ($this->isClosure($handler)) {
            $paramMap  = $this->getFunctionArgumentsNames($handler);
            $arguments = $this->getFunctionArguments(
                $paramMap,
                $route->getParameters(),
                $route->getPlaceholders()
            );

            return call_user_func_array($handler, $arguments);
        }

        return $this->dispatchNotFound();
    }
773786
public function createView(RouterInterface $router, $route, $params)
    {
        $view = new View();

        $view->count = $this->getNbPages();
        $view->currentPage = $this->getCurrentPage();
        $view->pages = $this->getPagerLinks($router, $route, $params);
        /** @noinspection PhpParamsInspection */
        $view->first = reset($view->pages);
        /** @noinspection PhpParamsInspection */
        $view->last = end($view->pages);
        $view->next = $this->hasNextPage() ? $view->pages[$view->currentPage + 1] : null;
        $view->prev = $this->hasPreviousPage() ? $view->pages[$view->currentPage - 1] : null;

        return $view;
    }
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;
    }
265915
public function route($route, $title, $parameters = array(), $order = null, $attributes = array())
    {
        if (func_num_args() == 4) {
            $arguments = func_get_args();

            return $this->add([
                'route' => [array_get($arguments, 0), array_get($arguments, 2)],
                'title' => array_get($arguments, 1),
                'attributes' => array_get($arguments, 3)
            ]);
        }

        $route = array($route, $parameters);

        $item = MenuItem::make(
            compact('route', 'title', 'parameters', 'attributes', 'order')
        );

        $this->items[] = $item;

        return $item;
    }
922674
protected function replaceRoot($route, $domain, &$parameters)
    {
        return $this->replaceRouteParameters($this->getRouteRoot($route, $domain), $parameters);
    }
260231
public function handle(RouteInterface $route)
    {
        $params = [];

        // create the regex that matches paths against the route
        $patternRegex = $this->createRouteRegex($route, $route->getPattern(), $params);

        // if the route regex matches the current request path
        if (preg_match($patternRegex, $route->getRoute(), $matches)) {
            if (count($matches) > 1) {
                // remove the first match (which is the full route match)
                array_shift($matches);

                // use the extracted parameters as the arguments' keys and the matches as the arguments' values
                return array_combine($params, $matches);
            } else {
                return [];
            }
        }
        // if the route regex does not match the current request path returns null
    }
867111
private function call(ServerRequestInterface $serverRequest, Route $route)
    {
        ob_start();

        try {
            $result = call_user_func(
                [
                    $this->container->resolve($route->getClass(), null),
                    $route->getMethod()
                ],
                new Request(
                    $serverRequest,
                    $this->container->get(ResponseFactoryInterface::class),
                    $this->container->get(ViewFactory::class),
                    $route
                )
            );

            if ($result instanceof ResponseInterface) {
                $response = $result;
            } else {
                $output = ob_get_contents();

                $response = $this->responseFactory->createResponse(200);
                $response->getBody()->write($result === null ? (string)$output : (string)$result);
            }

            ob_end_clean();
        } catch (\Exception $e) {
            ob_end_clean();
            throw $e;
        }

        return $this->addHeaders($response, $route);
    }
1326655
private function findRoute(string $uri, string $method): RouteInterface
    {
        $matches = [];
        $route = new NullRoute();

        foreach ($this->routes as $value) {
            $urlMatch = \preg_match('`^'.\preg_replace($this->matchTypes, $this->types, $value->url).'/?$`', $uri, $matches);
            $methodMatch = \strpos($value->method, $method);

            if ($urlMatch && $methodMatch !== false) {
                $route = clone $value;
                $this->routeMatches = $matches;
                break;
            }
        }

        return $route;
    }
1328009
public function match(ServerRequestInterface $request) : RouterMatch
    {
        $path = $request->getUri()->getPath();
        $syContext = new RequestContext('/');
        $syMatcher = new UrlMatcher($this->syRouteCollection, $syContext);
        try {
            $params = $syMatcher->match($path);
        } catch (\Throwable $e) {
            throw new HttpException(404, "No route matched for path $path",
                null, $e);
        }
        
        $matchedRouteName = $params['_route'];
        unset($params['_route']);
        $route = $this->routeProvider->getRouteFromName($matchedRouteName);
        $routerMatch = new RouterMatch($route, $params);
        return $routerMatch;
    }
53043
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        try {
            $route = $this->matchRoute($request);
        } catch (RouteException $e) {
            throw new RouterException("Invalid route definition", $e->getCode(), $e);
        }

        if (empty($route)) {
            throw new RouteNotFoundException($request->getUri());
        }

        return $this->container->get(ScopeInterface::class)->runScope(
            [RouteInterface::class => $route],
            function () use ($route, $request) {
                return $route->handle($request);
            }
        );
    }
559258
public function execute(Request $request, Route $route, $parameters)
    {
        $request->attributes->set('_controller', $this->getControllerCallback());
        $app = Facade::getFacadeApplication();
        $controllerResolver = $app->make(ApplicationAwareControllerResolver::class);
        $callback = $controllerResolver->getController($request);
        $argumentsResolver = $app->make(ArgumentResolver::class);

        $arguments = $argumentsResolver->getArguments($request, $callback);
        $controller = $callback[0];
        $method = $callback[1];

        if (method_exists($controller, 'on_start')) {
            $controller->on_start();
        }

        if (method_exists($controller, 'runAction')) {
            $response = $controller->runAction($method, $arguments);
        } else {
            $response = call_user_func_array([$controller, $method], $arguments);
        }

        if ($response instanceof Response) {
            // note, our RedirectResponse doesn't extend Response, it extends symfony2 response
            return $response;
        }

        if ($response instanceof AbstractView) {
            $content = $response->render();
        } else if (method_exists($controller, 'getViewObject')) {
            $content = null;
            $view = $controller->getViewObject();
            if (is_object($view)) {
                $view->setController($controller);
                if (isset($view) && $view instanceof AbstractView) {
                    $content = $view->render();
                }
            }
        } else {
            $content = $response;
        }

        if (is_object($content)) {
            return $content;
        }

        $response = new Response();
        $response->setContent($content);
        return $response;
    }
203864
public function forwardToRoute($route, $method, array $parameters = [])
    {
        return $this->forward($this['url_generator']->generate($route, $parameters), $method);
    }