creates matching route

@param   \stubbles\webapp\routing\CalledUri  $calledUri
@param   \stubbles\webapp\routing\Route      $route
@return  \stubbles\webapp\routing\ResolvingResource
5021
private function resolveResource(CalledUri $calledUri, Route $route): ResolvingResource
    {
        return new ResolvingResource(
                $this->injector,
                $calledUri,
                $this->collectInterceptors($calledUri, $route),
                $this->supportedMimeTypes($route),
                $route
        );
    }
6966
public function dispatch($method, $uri)
    {
        $routeInfo = $this->dispatcher->dispatch($method, $uri);

        if($routeInfo[0] === Dispatcher::NOT_FOUND) {

            $this->filterRequest('*', $method);

            $routeInfo = $this->dispatcher->dispatch($method, '*');

            if(!$routeInfo[0]) {
                throw new Exception("Route [ {$uri} ] not found.");
            }
        }

        if($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
            $method = $_SERVER['REQUEST_METHOD'];
            throw new Exception("[ $method ] method not allowed.");
        }

        if($routeInfo[0] === Dispatcher::FOUND) {
            $handler = $routeInfo[1];
            $params = $routeInfo[2];

            if(!empty($filterResponse = $this->filterRequest($uri, $method))) {
                return $filterResponse;
            }

            return $this->methodDispatcher($handler, $params);
        }
    }
749322
public function dispatch(Route $route)
    {
        $callback = $route->getCallback();
        $params = array_values($route->getData());

        if ($callback instanceof Closure) {
            return $this->container->resolveClosure($callback, $params);
        }

        $class = $this->container->make($callback[0]);
        return $this->container->resolveMethod($class, $callback[1], $params);
    }
416239
public static function create(RouteCollection $routes, ?string $prefix = null): self
    {
        $uriFactory = new UriFactory();

        return new self($routes, $uriFactory, $prefix);
    }
945573
public function matches(CalledUri $calledUri): bool
    {
        if (!$this->matchesPath($calledUri)) {
            return false;
        }

        if (in_array($calledUri->method(), $this->allowedRequestMethods)) {
            return true;
        }

        if (in_array(Http::GET, $this->allowedRequestMethods)) {
            return $calledUri->methodEquals(Http::HEAD);
        }

        return false;
    }
1018928
function create($route) {
        $route->pattern = $this->parser->trimPath($route->pattern);
        return parent::create($route);
    }
285627
public function handle( $requestUri )
    {
        $url = $this->_di->getService( "url" );

        /**
         * Remove the uri prefix from the request uri
         * (the uri prefix is added when route is created)
         */
        $requestUri = str_replace( $url->getUriPrefix(), "", $requestUri );

        $request_route = $this->_createRoute( ["uri" => $requestUri] );

        /**
         * Passing the uri to the get function in the url service to make sure the uri:s have a consistent format
         */
        //$request_route->setUri( $url->get( $request_route->getUri() ) );

        $request_route_uri_fragments = explode( "/", $request_route->getUri() );

        foreach ($this->_routeDefinitions as $routeDefinition)
        {
            $route = call_user_func($routeDefinition);

            /**
             * Passing the uri to the get function in the url service to make sure the uri:s have a consistent format
             */
            //$route->setUri( $url->get( $route->getUri() ) );

            $route_uri_fragments = explode( "/", $route->getUri() );

            /**
             * Check if request uri and route uri has the same number of fragments.
             * If not, continue to next route.
             */
            if ( count($route_uri_fragments) != count($request_route_uri_fragments) )
            {
                continue;
            }

            $params = array();

            /**
             * Compare every fragment of the uris
             */
            for ( $i = 0; $i < count($route_uri_fragments); $i++ )
            {
                /**
                 * Parameters are not compared
                 */
                if ( $route_uri_fragments[$i] == "{param}" )
                {
                    $params[] = $request_route_uri_fragments[$i];

                    continue;
                }

                /**
                 * If a fragment is not equal -> continue to next route
                 */
                if ( $route_uri_fragments[$i] != $request_route_uri_fragments[$i] )
                {
                    continue 2;
                }
            }

            $route->setParams( $params );

            /**
             * We have a match!
             */
            $this->_matchRoute = $route;

            return;
        }

        /**
         * No match :(
         * If not found route has been set -> set as out match route
         */
        if ( isset($this->_notFoundRoute) )
        {
            $this->_matchRoute = $this->_notFoundRoute;

            return;
        }

        /**
         * With no other options, we set the match route to a default route
         */
        $this->_matchRoute = new Route();
    }
545346
public function createFinding(Route $route = null, array $parameters = null, ServerRequestInterface $request = null)
	{
		return $this->create('finding', array($route, $parameters, $request));
	}
743128
public function resolve(Router $router, $uri, $method)
	{
		// get all register routes with the same request method
		$routes = $router->getRoutesByMethod($method);
		// remove trailing and leading slash
		$requestedUri = trim(preg_replace('/\?.*/', '', $uri), '/');
		// loop trough the posible routes
		foreach ($routes as $route) {
			$matches = array();

			// if the requested route matches one of the defined routes
			if ($route->getUrl() === $requestedUri || preg_match('~^'.$route->getUrl().'$~', $requestedUri, $matches)) {
				$argumentArray = array();
				$arguments = $this->getArguments($matches);

				// check if there route has arguments
				if (is_array($route->getArguments()) && count($route->getArguments()) > 0) {
					// loop trough all the arguments
					foreach ($route->getArguments() as $key => $argument) {
						// if the argument exists set the value
						if (isset($arguments[$key])) {
							$argumentArray[$argument] = $arguments[$key];
						} else {
							// setting the value to null should only occure when we use an optional parameter
							$argumentArray[$argument] = null;
						}
					}
				}

				return [
					'code' => Route::STATUS_FOUND,
					'handler' => $route->getAction(),
					'arguments' => $argumentArray
				];
			}
		}

		return [
			'code' => Route::STATUS_NOT_FOUND,
			'handler' => null,
			'arguments' => []
		];
	}
1129269
public function set($methods, $route, callable $callable)
	{
		if (is_string($methods)) {
			$methods = [$methods];
		}

		foreach ($methods as $method) {
			$this->add($method, $route, $callable);
		}

		return $this;
	}
1262276
public function loadRoute($uri)
    {
        $route = $this->getRoute($uri);

        if($route)
        {
            $controllerPath = $this->getControllerPath($route);

            if($controllerPath)
            {
                require $controllerPath;

                $controller = $this->initController($route->getControllerName(), $route->getControllerPath());
                $this->runController($controller, $route->getAction(), $route->getValues());
            }
        }
        else
        {
            throw new \Exception("No route was found that matched the requested URI.", 1);
        }
    }
13509
public function getUri($route, $full = false)
    {
        $route = $this->validate($route);
        $path = $this->getPathValidated($route);
        if (is_string($path)) {
            return new Message\Uri($path);
        }
        if ($full) {
            $uri = $this->request->getUri()->withPath($this->request->pathToString($path));
        } else {
            $uri = new Message\Uri($this->request->pathToString($path));
        }
        $uri = $uri->withQuery($this->buildQuery($route->getQuery()))
            ->withFragment($route->getFragment());
        return $uri;
    }
1243245
protected function createRoute($methods, $uri, $action)
    {
        // Transform an action controller to a Closure action
        if ($this->isActionController($action)) {
            $action = $this->convertToControllerAction($action);
        }

        // Create new route
        $route = $this->newRoute(
            $methods, $uri, $action
        );

        return $route;
    }
1171591
public function redirectToRouteAction(Request $request, $route, $permanent = false)
    {
        if ('' === $route) {
            throw new HttpException($permanent ? 410 : 404);
        }

        $attributes = array_merge($request->attributes->get('_route_params'), $request->query->all());
        unset($attributes['route'], $attributes['permanent']);

        return new RedirectResponse(
            $this->container->get('router')->generate($route, $attributes, UrlGeneratorInterface::ABSOLUTE_URL),
            $permanent ? 301 : 302,
            ['Cache-Control' => 'private']
        );
    }
1134587
public function get(callable $totalAmountCallable, callable $resultsCallable, $route, $className)
    {
        try {
            QueryObject::assert(
                $this->serializer,
                $this->fields,
                $this->included,
                $this->sorting,
                $this->errorBag,
                $className
            );
            $totalAmount = $totalAmountCallable();

            if ($totalAmount > 0 && $this->page->size() > 0 && $this->page->number() > ceil($totalAmount / $this->page->size())) {
                return $this->resourceNotFound(
                    new ErrorBag([new OufOfBoundsError($this->page->number(), $this->page->size())])
                );
            }

            $links = $this->pagePaginationLinks(
                $route,
                $this->page->number(),
                $this->page->size(),
                $totalAmount,
                $this->fields,
                $this->sorting,
                $this->included,
                $this->filters
            );

            $results = $resultsCallable();

            $paginatedResource = new PaginatedResource(
                $this->serializer->serialize($results, $this->fields, $this->included),
                $this->page->number(),
                $this->page->size(),
                $totalAmount,
                $links
            );

            $response = $this->response($paginatedResource);
        } catch (Exception $e) {
            $response = $this->getErrorResponse($e);
        }

        return $response;
    }
424414
public function connect($route, $callable){
    if(!is_string($route)){
      throw new \InvalidArgumentException("Route to connect to callable musts be provided as a string");
    }
    if(!is_callable($callable)){
      throw new \InvalidArgumentException("Provided callable for $route is not valid.");
    }
    $this->routes[$route] = $callable;
  }
661403
public function add(ParsedRoute $route)
    {
        foreach ($route->getMethods() as $method) {
            $this->routes[$method][] = $route;

            if (!empty($route->getName())) {
                $this->namedRoutes[$route->getName()] =& $route;
            }
        }
    }