Find the first route matching a given request.

@param  \Illuminate\Http\Request $request

@return \Illuminate\Routing\Route
@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
435701
public function match(Request $request)
    {
        $hasWpParams = $request->path() == '/' && ($request->has('p') || $request->has('post_id'));

        if ($hasWpParams && $route = $this->findMatchingWordPressPost($request)) {
            return $route;
        }

        try {
            return parent::match($request);
        } catch (NotFoundHttpException $e) {

            if ($route = $this->findMatchingWordPressPost($request)) {
                return $route;
            }

            throw $e;
        }
    }
1236759
public function getMatchingRoute($routes, Request $request)
    {
        foreach ($routes as $matchingRoute) {
            if ($matchingRoute->matches($request)) {
                return $matchingRoute;
            }
        }

        return null;
    }
1306289
protected function run(Request $request)
	{
		if (!$this->routesConfigured) {
			$this->adaptor->configureRoutes($this->routeProvider);
			$this->routesConfigured = true;
		}

		$handler = $this->adaptor->route($request);

		if ($handler === false) {
			return $this->chain($request);
		}

		// Setup any remaining chained parts of the dispatch for future dispatch
		$request = $request->withAttribute('dispatch.handler', $this->resolver->shift($handler));

		// Resolve the handler into something callable
		$dispatchable = $this->resolver->resolve($handler, $resolutionType);

		$parameters = [
			$dispatchable,
			$resolutionType,
			DispatchAdaptorInterface::SOURCE_ROUTER,
			$request
		];
		$response = $this->getResponseObject();
		if ($response !== null) {
			$parameters[] = $response;
		}
		return $this->dispatcher->dispatch(...$parameters) ?: $this->chain($request);
	}
479953
public function queryAction(Request $request)
    {
        $geolocatorName = $request->get('providerName');
        $query = $request->get('query');

        try {
            $geolocator = $this->geolocatorManager->get($geolocatorName);
        } catch (GeolocatorNotFoundException $e) {
            throw new NotFoundHttpException(
                sprintf(
                    'Wrapped "%s"',
                    $e->getMessage()
                ),
                $e
            );
        }

        $res = $geolocator->locate($query);

        return new JsonResponse(['_embedded' => ['locations' => $res->toArray()]]);
    }
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
        );
    }
245371
public function match(RequestInterface $request)
    {
        foreach ($this->routes as $name => $route) {
            if (!$route->match($request)) {
                continue;
            }

            foreach ($route->arguments() as $key => $value) {
                $request->query()
                    ->set($key, $value);
            }

            $request->language($request->query()->get('language'));
            $request->format($request->query()->get('format'));

            $request->route($name);

            $this->defaults = [
                'host' => $request->baseName(),
                'route' => $name,
                'language' => $request->language(),
                'format' => $request->format()
            ];

            return $route->controller();
        }

        throw new RouterException('Route for "' . $request->path() . '" not found!');
    }
923903
public function getRouting(Request $request)
    {
        // Check if router class has been defined in config parameters
        if ($this->getConfig()->hasParameter('routing')) {
            $routerClass = $this->getConfig()->getParameter('routing');

            $router = new $routerClass();

            return $router;
        }

        $router = new Router($request);

        return $router;
    }
867830
public function getRedirectFor(Request $request)
    {
        $redirects = $this->redirector->getRedirectsFor($request);

        collect($redirects)->each(function ($redirects, $missingUrl) {
            $this->router->get($missingUrl, function () use ($redirects, $missingUrl) {
                $redirectUrl = $this->determineRedirectUrl($redirects);
                $statusCode = $this->determineRedirectStatusCode($redirects);

                event(new RouteWasHit($redirectUrl, $missingUrl, $statusCode));

                return redirect()->to(
                    $redirectUrl,
                    $statusCode
                );
            });
        });

        try {
            return $this->router->dispatch($request);
        } catch (Exception $e) {
            event(new RedirectNotFound($request));

            return;
        }
    }
363623
public function ajaxControllerAction(Request $request)
    {
        $operation = $request->request->get('operation') ? $request->request->get('operation') : $request->query->get(
            'operation'
        );

        if (!$operation) {
            throw new NotFoundHttpException();
        }

        return new JsonResponse($this->$operation());
    }
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;
        }
    }
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;
    }
1198683
public function dispatchToRoute(Request $request)
    {
        // First we will find a route that matches this request. We will also set the
        // route resolver on the request so middlewares assigned to the route will
        // receive access to this route instance for checking of the parameters.
        $route = $this->findRoute($request);
        $request->setRouteResolver(function () use ($route) {
            return $route;
        });
        $this->events->fire('router.matched', [$route, $request]);
        
        if (is_null($response)) {
            $response = $this->runRouteWithinStack(
                $route, $request
            );
        }
        
        return $this->prepareResponse($request, $response);
    }
909005
public function execute($request)
	{
		$match = $this->lookup($request->getUrl()->getPath());
		$controller = $this->controller($match->getName());
		return $controller->execute(new RoutedRequest($request, $match, $this));
	}
329553
public function dispatch(Request $request)
    {
        $this->logger->debug('Dispatching request');
        try {
            /**
             * @var \Shade\Router\RouterInterface $router
             */
            $router = $this->serviceContainer->getService(ServiceContainer::SERVICE_ROUTER);
            $route = $router->route($request);
            if (!isset($this->primaryRequest)) {
                $this->primaryRequest = $request;
                $logMessage = 'Route found for primary request';
            } else {
                $logMessage = 'Route found for secondary request';
            }
            if (!isset($this->primaryRoute)) {
                $this->primaryRoute = $route;
            }
        } catch (Exception $e) {
            $this->logger->debug('Route not found');
            $response = new Response();
            $response->setCode(404);

            return $response;
        }

        $this->validateRoute($route);
        $this->logger->debug(
            $logMessage,
            [
                'controller' => $route->controller(),
                'action' => $route->action(),
                'args' => $route->args(),
            ]
        );
        $controllerClass = $route->controller();
        $actionName = $route->action();
        $actionArguments = $this->getMethodArguments($controllerClass, $actionName);

        if (method_exists($controllerClass, '__construct')) {
            $constructorArguments = $this->getMethodArguments($controllerClass, '__construct');
        }

        if (empty($constructorArguments)) {
            $controller = new $controllerClass();
        } else {
            $controllerReflection = new \ReflectionClass($controllerClass);
            $controller = $controllerReflection->newInstanceArgs($constructorArguments);
        }

        if (!($controller instanceof Controller)) {
            throw new Exception(
                "'{$controllerClass}' must inherit '\\Shade\\Controller'."
            );
        }

        /**
         * @var \Shade\Controller $controller
         */
        $controller->setControllerDispatcher($this);
        $controller->setView($this->serviceContainer->getService(ServiceContainer::SERVICE_VIEW));
        $controller->setCurrentRequest($request);
        $controller->setCurrentRoute($route);
        $controller->setPrimaryRequest($request);
        $controller->setPrimaryRoute($route);

        /**
         * @var Response $response
         */
        $response = call_user_func_array([$controller, $actionName], $actionArguments);
        if (!$response instanceof Response) {
            throw new Exception(
                "Executed controller hasn't returned instance of \\Shade\\Response. "
                .ucfirst(gettype($response)).' has been returned.'
            );
        }

        if (!$response->getCode()) {
            $response->setCode(200);
        }

        return $response;
    }
917542
public function dispatch(Request $request)
    {
        $this->currentRoute = null;

        $this->container->instance(Request::class, $request);

        $this->routesDispatched++;

        try {
            $response = $this->adapter->dispatch($request, $request->version());
        } catch (Exception $exception) {
            if ($request instanceof InternalRequest) {
                throw $exception;
            }

            $this->exception->report($exception);

            $response = $this->exception->handle($exception);
        }

        return $this->prepareResponse($response, $request, $request->format());
    }
1355507
public function findHttpRoute(Request $request)
    {
        $route = Assist::extractBeforeNeedle($request->queryPath(), '?');

        if (!$this->has($route)) {
            throw new Base('No route has been found for this url');
        }

        $data = $this->find($route);
        if (!in_array(strtolower(strtolower($request->method())), array_keys($data))) {
            throw new Base(
                'This route only accepts the "' .
                implode(', ', array_keys($data)) . '" http method(s)'
            );
        }

        $httpMethod = strtolower($request->method());

        return new Parameters($data[$httpMethod]);
    }
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));
        }
    }