Add a route to the routing adapter.

@param string|array          $methods
@param string                $uri
@param string|array|callable $action

@return mixed
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);
    }
1294149
private function addRoute($method, $uri, $controller, $action)
    {
        // Prefix route uri, concat it and clear
        if (strlen($this->prefixUri) > 0) {
            $uri = $this->prefixUri . $uri;
            $this->prefixUri = '';
        }

        // Compatible: has no namespace
        if (strrpos($controller, '\\', 1) === false) {
            $controller = 'App\\Controllers\\' . $controller;
        }

        $items = $uri ? explode('/', ltrim($uri, '/')) : [];

        $this->routes[] = [
            'method'     => $method,
            'count'      => count($items),
            'controller' => $controller,
            'action'     => $action,
            'params'     => $items,
        ];
    }
829210
public function addRoute($method, $path, $action)
    {
        $route = (new Route($this->conditions, $this->container))
            ->setMethods($method)
            ->setPath($path)
            ->setAction($action)
            ->setRouter($this);

        return $this->routes->add($route);
    }
1140329
public function addRoute(array $methods, array $versions, $uri, $action)
    {
        $this->createRouteCollections($versions);

        $route = new Route($methods, $uri, $action);
        $route->where($action['where']);

        foreach ($versions as $version) {
            $this->routes[$version]->add($route);
        }

        return $route;
    }
1331804
public static function parse($uri, $action)
    {
        // If no action is passed in right away, we assume the user will make use of
        // fluent routing. In that case, we set a default closure, to be executed
        // if the user never explicitly sets an action to handle the given uri.
        if (is_null($action)) {
            return static::missingAction($uri);
        }

        // If the action is already a Closure instance, we will just set that instance
        // as the "uses" property, because there is nothing else we need to do when
        // it is available. Otherwise we will need to find it in the action list.
        if (is_callable($action, true)) {
            return ! is_array($action) ? ['uses' => $action] : [
                'uses' => $action[0].'@'.$action[1],
                'controller' => $action[0].'@'.$action[1],
            ];
        }

        // If no "uses" property has been set, we will dig through the array to find a
        // Closure instance within this list. We will set the first Closure we come
        // across into the "uses" property that will get fired off by this route.
        elseif (! isset($action['uses'])) {
            $action['uses'] = static::findCallable($action);
        }

        if (is_string($action['uses']) && ! Str::contains($action['uses'], '@')) {
            $action['uses'] = static::makeInvokable($action['uses']);
        }

        return $action;
    }
1134480
protected function createRoute( $methods, $uri, $action )
	{
		// If the route is routing to a controller we will parse the route action into
		// an acceptable array format before registering it and creating this route
		// instance itself. We need to build the Closure that will call this out.
		if ( $this->actionReferencesController( $action ) )
			$action = $this->convertToControllerAction( $action );

		$route = $this->newRoute( $methods, $this->prefix( $uri ), $action );

		// If we have groups that need to be merged, we will merge them now after this
		// route has already been created and is ready to go. After we're done with
		// the merge we will be ready to return the route back out to the caller.
		if ( $this->hasGroupStack() )
			$this->mergeGroupAttributesIntoRoute( $route );

		$this->addWhereClausesToRoute( $route );

		return $route;
	}
412932
public function match(array $methods, $path, $action)
    {
        $methods = $this->normalizeRequestMethods($methods);

        return $this->addRoute($methods, $path, $action);
    }
242524
public function addRoute($method, $uri, $action)
    {
        $action = $this->parseAction($action);

        $attributes = null;

        if ($this->hasGroupStack()) {
            $attributes = $this->mergeWithLastGroup([]);
        }

        if (isset($attributes) && \is_array($attributes)) {
            if (isset($attributes['prefix'])) {
                $uri = \trim($attributes['prefix'], '/').'/'.\trim($uri, '/');
            }

            if (isset($attributes['suffix'])) {
                $uri = \trim($uri, '/').\rtrim($attributes['suffix'], '/');
            }

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

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

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

        if (\is_array($method)) {
            foreach ($method as $verb) {
                $this->routes[$verb.$uri] = ['method' => $verb, 'uri' => $uri, 'action' => $action];
            }
        } else {
            $this->routes[$method.$uri] = ['method' => $method, 'uri' => $uri, 'action' => $action];
        }
    }
1098393
protected function addRoute($method, $uri, $action)
    {
        $uri = '/'.trim($uri, '/');
        if (is_string($action)) {
            $action = ['uses' => $action];
        }

        if (! is_array($action) || empty($action['uses']) || ! is_string($action['uses'])) {
            throw new \Exception('错误的路由' . $uri);
        }

        $this->routeCollector->addRoute($method, $uri, $action);
    }
752293
protected function newRoute( $methods, $uri, $action )
	{
		return ( new Route( $methods, $uri, $action ) )->setRouter( $this );
	}
913867
public function request($method, $uri, array $parameters = [])
    {
        return $this->container->get(AdapterInterface::class)
            ->request($method, $uri, $parameters);
    }
391017
public function add($uri, $method = Route::METHOD_ALL, $name = null, $prefix = false)
    {
        if ($prefix) {
            $uri = $this->prefix . $uri . $this->postfix;
        }

        $route = $this->parser->parse($uri, $method);
        if ($name === null || is_int($name)) {
            $name = count($this->routes);
        } elseif (!is_string($name)) {
            throw new \InvalidArgumentException('$name must be a string, integer or null.');
        }
        $this->routes[$name] = $route;
        if ($route->isStatic()) {
            if (!isset($this->staticRoutes[$uri])) {
                $this->staticRoutes[$uri] = [
                    $method => $route
                ];
            } else {
                $this->staticRoutes[$uri][$method] = $route;
            }
        }
        $route->set($this->globalValues);

        return $route;
    }
523823
public function delete($uri, $action)
    {
        $uri = $this->buildUri($uri);

        return $this->addResponseType(Route::delete($uri, $action));
    }
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;
    }
1250250
protected function registerRoute($method, $uri, $action = null)
    {
        if (! is_array($action)) {
            $action = array_merge($this->attributes, $action ? ['uses' => $action] : []);
        }

        return $this->router->{$method}($uri, $this->compileAction($action));
    }
96844
private function addRoute($types = '', $uri, $action = [])
    {

        if (is_string($action)) {
            $action = ['_controller' => $action];
        }

        if (is_array($action)) {
            if (isset($action['as'])) {
                AsCollector::addAs($action['as'], $uri);
            }
        }

        $types = (array)$types;

        foreach ($types as $type) {
            $type = mb_convert_case($type, MB_CASE_UPPER);

            $add = [
                'uri' => isset(static::$firing['when']) ? $this->createWhenUri($uri) : $uri,
                'action' => $action
            ];;

            // add group parameter to action variable
            if (isset(static::$firing['group'])) {
                $add['group'] = static::$firing['group'];
            }

            // add to collection
            static::$routes[$type][] = $add;
        }
        return $this;
    }
1134843
protected function buildUri(Actions\ActionsInterface $action, array $requestParams)
    {
        $uri = $this->connection->getEndpoint() . '/' . $action->getAction();

        if ($this->connection->getHttpMethod() === Request::METHOD_GET) {
            $uri .= '?' . http_build_query($requestParams);
        }

        return new Uri($uri);
    }