Dispatch a route for the given HTTP Method / URI.

@param $httpMethod
@param $uri
@return mixed|null
198706
public function dispatch($httpMethod, $uri)
    {
        list($handler, $filters, $vars) = $this->dispatchRoute($httpMethod, trim($uri, '/'));

        list($beforeFilter, $afterFilter) = $this->parseFilters($filters);

        if (($response = $this->dispatchFilters($beforeFilter)) !== null) {
            return $response;
        }

        $resolvedHandler = $this->handlerResolver->resolve($handler);
        $vars['request'] = $this->getRequest();
        $reflection = new ReflectionMethod($resolvedHandler[0], $resolvedHandler[1]);
        $reflectionVariables = $this->getReflectionVars($reflection, $vars);
        $this->authorizeRequest();
        $this->validateRequest($reflectionVariables);
        $response = call_user_func_array(
            $resolvedHandler,
            $reflectionVariables
        );

        return $this->dispatchFilters($afterFilter, $response);
    }
859564
public function action($removeHttpMethod = true)
    {
        if ($action = $this->router->currentRouteAction()) {
            $action = last(Str::parseCallback($action, null));

            if ($removeHttpMethod) {
                $action = str_replace(['get', 'post', 'patch', 'put', 'delete'], '', $action);
            }

            return Str::snake($action, '-');
        }

        return null;
    }
1212009
public function _dispatch($action, $httpMethod, $vars = array())
    {
        $this->_action = $action;
        $this->_data = $_POST;
        $this->_params = array_merge(Atomik::get('request'), $vars);
        $this->_httpMethod = $httpMethod;
        
        $this->preDispatch();
        $result = $this->_execute($action, $this->_params);
        $this->postDispatch($result);
        return $result;
    }
1209539
public function prepare ($uri, $method)
	{
		try {
			$this->router = new Router($uri, $method, $this->params);

			if ($uri === $this->config->base_uri) {
				return $this->use_root_controller();
			}

			$this->router->parse();

			if ($this->router->route->is_empty()) {
				return $this->use_root_controller();
			} else {
				$this->controller_name = 'Controllers\\' . $this->router->route->join('\\');

				if (!class_exists($this->controller_name)) {
					throw new Exceptions\RouterException;
				}
			}

		} catch (Exceptions\RouterException $e) {
			$this->log->debug($e->getMessage());

			if (!empty($this->config->spa)) {
				# Route all not found controllers to root, if single page application
				return $this->use_root_controller();
			}

			$this->use_not_found_controller();
		}
	}
314386
protected function createRoute($methods, $uri, $action)
    {
        $route = parent::createRoute($methods, $uri, $action);
        if (! empty($this->groupStack)) {
            $route = $this->mergePriority($route);
        }

        return $route;
    }
1115360
public function addRoute($method, $uri, $action)
    {
        $uri = strtolower($uri);
        $action = $this->parseAction($action);

        if (isset($this->groupAttributes)) {
            if (isset($this->groupAttributes['prefix'])) {
                $uri = trim($this->groupAttributes['prefix'], '/').'/'.trim($uri, '/');
            }

            $action = $this->mergeGroupAttributes($action);
        }

        $uri = '/'.trim($uri, '/');

        if (isset($action['as'])) {
            $this->namedRoutes[$action['as']] = $uri;
        }

        $this->routes[$this->identifier] = ['method' => $method, 'uri' => $uri, 'action' => $action];
        $this->identifier++;

        return $this;
    }
1063262
public function dispatch( Route $route, Request $request, $controller, $method )
	{
		$instance = $this->makeController( $controller );

		return $this->callWithinStack( $instance, $route, $request, $method );
	}
457719
public function route($uri = null)
    {
        if ($uri === null) {
            $uri = $this->getAppUri();
        }
        //$uri = ltrim(preg_replace('/^([^&]*)&.*$/', '$1', $uri), '/');
        
        $urlElements = parse_url($uri);
        $uri      = isset($urlElements['path'])     ? $urlElements['path']     : '';
        $query    = isset($urlElements['query'])    ? $urlElements['query']    : null;
        $fragment = isset($urlElements['fragment']) ? $urlElements['fragment'] : null;
        $urlTab = explode('/', trim($uri, ' /'));
        $request = Container::getRequest();
        $request->setUri($uri);
        $request->setBaseUrl($this->getBaseUrl());
        $controller = array_shift($urlTab);
        $action = array_shift($urlTab);
        $request->setController($controller ? $controller : self::DEFAULT_CONTROLLER);
        $request->setAction($action ? $action : self::DEFAULT_ACTION);
        while (count($urlTab)) {
            $key = trim(array_shift($urlTab));
            $value = array_shift($urlTab);
            if ($value !== null) {
                $request->setParam($key, $value);
            }
        }
        if ($query !== null) {
            $params = null;
            parse_str($query, $params);
            foreach ($params as $key => $value) {
                $request->setParam($key, $value);
            }
        }
        
        return $this;
    }
228562
protected function addRoute($methods, $uri, $action)
	{
		$route = $this->createRoute($methods, $uri, $action);

		$route->setPrefixUri($this->processGroupsUri());

		$this->routes->addRoute($route);

		return $route;
	}
599529
public function dispatch($route, $controller, $method)
    {
        if (method_exists($controller, $method)) {
            return $this->container->call(
                [$controller, $method],
                $this->getMethodArguments($route)
            );
        }

        return $controller->missingMethod($method);
    }
526951
public static function getRoute($route, $method=null) {
// 		$routes	= static::getRoutes();
		if( $method ) {
			return isset(static::$routes[$route][$method]) ? static::$routes[$route][$method] : null;
		}
		foreach( static::getKnownMethods() as $method ) {
			if( isset(static::$routes[$route][$method]) ) {
				return static::$routes[$route][$method];
			}
		}
		return null;
	}
730250
protected function dispatchRouter($method, $path)
    {
        $router = $this->container['router'];
        $logger = $this->container['logger'];

        $logger->debug('Router dispatch.', ['method' => $method, 'path' => $path]);

        $router->init();
        $route_info = $router->dispatch($method, $path);

        $handler = null;
        $vars = [];

        switch ($route_info[0]) {
        case RouteDispatcher::NOT_FOUND:
            $logger->debug('Routing failed. Not Found.');
            throw new HttpNotFoundException('404 Not Found');
            break;
        case RouteDispatcher::METHOD_NOT_ALLOWED:
            $logger->debug('Routing failed. Method Not Allowd.');
            throw new HttpMethodNotAllowedException('405 Method Not Allowed');
            break;
        case RouteDispatcher::FOUND:
            $handler = $route_info[1];
            $vars = $route_info[2];
            $logger->debug('Route found.', ['handler' => $handler]);
            break;
        }

        return [$handler, $vars];
    }
221487
public static function findRoute($uri) {
		if(self::$routes === array())
			self::load();

		$count = count($uri);

		$position = &self::$routes;
		for($i = 0; $i < $count; $i++) {
			if($i == $count - 1) {
				if(isset($position[$uri[$i]]) && isset($position[$uri[$i]]["route"])) {
					return $position[$uri[$i]]["route"];
				} else if(isset($position["*"]) && isset($position["*"]["route"])) {
					return $position["*"]["route"];
				} else {
					throw new ValidRouteNotFoundException;
				}
			} else {
				if(isset($position[$uri[$i]])) {
					$position = &$position[$uri[$i]]["children"];
				} elseif(isset($position["*"])) {
					$position = &$position["*"]["children"];
				} else {
					throw new ValidRouteNotFoundException;
				}
			}
		}

		throw new ValidRouteNotFoundException;
	}
811207
protected function newRoute($methods, $uri, $action)
    {
        return with(new Route($methods, $uri, $action))
            ->setRouter($this)
            ->setContainer($this->container);
    }
712661
public function route($method, $uri)
    {
        // Remove subfolder from URI if needed
        $baseDir = $this->get('___.baseDir');
        if ("/" !== $baseDir && 0 === strpos($uri, $baseDir)) {
            $uri = substr($uri, strlen($baseDir));
        }

        // Check which route is being used.
        $routings = $this->routings;
        $this->dispatcher = $this->dispatcher ?: \FastRoute\simpleDispatcher(function(\FastRoute\RouteCollector $r) use ($routings) {
            foreach ($routings as $name => $routing) {
                // 'GET', '/user/{id:\d+}', $routeName
                $r->addRoute($routing[0], $routing[1], $name);
            }
        });

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

        if (\FastRoute\Dispatcher::FOUND === $routeInfo[0]) {
            return array_slice($routeInfo, 1);
        }

        return null;
    }
17409
public function addRoute($methods, $uri, $action)
    {
        if (\is_string($action)) {
            $action = ['uses' => $action, 'controller' => $action];
        } elseif ($action instanceof Closure) {
            $action = [$action];
        }

        $action = $this->mergeLastGroupAttributes($action);

        $action = $this->addControllerMiddlewareToRouteAction($action);

        $uri = $uri === '/' ? $uri : '/'.\trim($uri, '/');

        if (! empty($action['prefix'])) {
            $uri = '/'.\ltrim(\rtrim(\trim($action['prefix'], '/').'/'.\trim($uri, '/'), '/'), '/');

            unset($action['prefix']);
        }

        $action['uri'] = $uri;

        return $this->adapter->addRoute((array) $methods, $action['version'], $uri, $action);
    }
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;
    }