Add AJAX route

@access public
@param string $patternUri
@param string|\callable $action
@paran string $name
@return Route
555794
public function ajax($patternUri, $action, $name)
    {
        $route = new Route("ajax", $patternUri, $action, $name);
        $this->container->addRoute($route);
        return $route;
    }
559475
public function get($uri, $action)
    {
        $uri = $this->buildUri($uri);

        return $this->addResponseType(Route::get($uri, $action));
    }
423142
public function options(string $uri, string $controller, string $action)
    {
        $this->addRoute('OPTIONS', $uri, $controller, $action);
    }
419418
public function get(string $uri, $action): self
    {
        $this->routes['GET'][$this->trimTrailingSlashes($uri)] = $action;

        return $this;
    }
1040478
public function options($pattern, $action, $name = null)
    {
        return $this->addRoute(['OPTIONS'], $pattern, $action, $name);
    }
1144471
public function addRoute($methods, $uri, $action)
    {
        if (is_string($action)) {
            $action = ['uses' => $action];
        } elseif ($action instanceof Closure) {
            $action = [$action];
        }

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

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

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

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

        $action['uri'] = $uri;

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

//        echo $action;
//        return $this->adapter->addRoute((array) $methods, $action['version'], $uri, $action);
        return $this->addRoute((array) $methods, $action['version'], $uri, $action);
    }
942461
public function addRoute($methods, $uri, $action)
    {
        // We do not keep routes in ApiRouter. Whenever a route is added,
        // we add it to Laravel's primary route collection
        $routes = app("router")->getRoutes();
        $prefix = config("api.prefix");

        if (empty($this->versions)) {
            if (($default = config("api.default_version")) !== null) {
                $versions = [$default];
            }
            else {
                $versions = [null];
            }

        }
        else {
            $versions = $this->versions;
        }


        // Add version prefix
        foreach ($versions as $version) {
            // Add ApiMiddleware to all routes
            $route = $this->createRoute($methods, $uri, $action);
            $route->middleware(ApiMiddleware::class);

            if ($version !== null) {
                $route->prefix($version);
                $route->name("." . $version);
            }

            if (!empty($prefix)) {
                $route->prefix($prefix);
            }

            $routes->add($route);

            // Options route
            $route = $this->createRoute(['OPTIONS'], $uri, function () {
                return [];
            });

            $route->middleware(ApiMiddleware::class);

            if ($version !== null) {
                $route->prefix($version);
                $route->name("." . $version);
            }

            if (!empty($prefix)) {
                $route->prefix($prefix);
            }

            $routes->add($route);
        }

        app("router")->setRoutes($routes);
    }
1136337
protected function createRoute($methods, $uri, $action)
    {
        if (is_callable($action)) {
            $action = array('uses' => $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.
        else if ($this->actionReferencesController($action)) {
            $action = $this->convertToControllerAction($action);
        }

        // 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.
        else if (! isset($action['uses'])) {
            $action['uses'] = $this->findActionClosure($action);
        }

        if (isset($action['middleware']) && is_string($action['middleware'])) {
            $action['middleware'] = explode('|', $action['middleware']);
        }

        $route = $this->newRoute(
            $methods, $uri = $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 (! empty($this->groupStack)) {
            $this->mergeGroupAttributesIntoRoute($route);
        }

        $this->addWhereClausesToRoute($route);

        return $route;
    }
616675
public function buildUri(array $params = null, $controller = null, $action = null, $prepareUri = true)
    {
        $request = Container::getRequest();
        $request->setBaseUrl($this->getBaseUrl());
        if ($prepareUri) {
            [$params, $controller, $action] = $this->prepareUri($params, $controller, $action);
        } else {
            $params = $params ?? [];
            $controller = $controller ?? self::DEFAULT_CONTROLLER;
            $action = $action ?? self::DEFAULT_ACTION;
        }
        if (!is_array($params)) {
            $params = [];
        }
        if (isset($params['controller']) && ($controller === self::DEFAULT_CONTROLLER)) {
            $controller = $params['controller'];
            unset($params['controller']);
        }
        if (isset($params['action']) && ($action === self::DEFAULT_ACTION)) {
            $action = $params['action'];
            unset($params['action']);
        }
        $hasParams = count($params);
        $hasController = $controller != self::DEFAULT_CONTROLLER;
        $hasAction = $action != self::DEFAULT_ACTION;
        $uri  = $hasParams || $hasAction || $hasController ? '/' . $controller : '/';
        $uri .= $hasParams || $hasAction ? '/' . $action : '';
        foreach ($params as $key => $value) {
            $uri .= '/' . $key . '/' . $value;
        }
        
        $uri = '/' . ltrim(rtrim($request->getBaseUrl(), '/') . $uri, '/');
        return $uri;
    }
1278564
protected function _createURL($base, $controller, $action, $params, $searchDefined = true)
    {
        $params['controller'] = $controller;
        $params['action'] = $action;
        foreach ($this->urlRoutes as $route => $defined) { // first check those with strict params.
            $cBase = $base;
            $preparedParams = $params;
            if ($searchDefined) {
                if (is_numeric($route)) {
                    continue; // first only get those with defined conditions.
                }
                $match = true;
                foreach ($defined as $def => $value) { // first check if those exact values match.
                    if (($value || '0' === $value) && (!isset($params[$def]) || $params[$def] != $value)) {
                        $match = false;
                    } else {
                        unset($preparedParams[$def]);
                        if ('module' == $def) {
                            if (substr($cBase, -1 * strlen($value . '/')) == $value . '/') { // remove module from base url if it's there
                                $cBase = substr($cBase, 0, strlen($cBase) - strlen($value . '/'));
                            }
                        }
                    }
                }
                if (!$match) {
                    continue;
                }
            }
            $match = true;
            preg_match_all('/\(\?<([a-z0-9_\-]+)>.*?\)/', is_numeric($route) ? $defined : $route, $matches);
            if (!$matches) {
                continue;
            }
            $toReplace = array('\/' => '/');
            foreach ($matches[1] as $k => $word) {
                $match = $match & isset($params[$word]);
                if ($match) {
                    $toReplace[$matches[0][$k]] = $params[$word];
                    unset($preparedParams[$word]);
                } else {
                    break;
                }
            }

            if ($match) {
                unset($preparedParams['module']);
                return $cBase . str_replace(array_keys($toReplace), array_values($toReplace), is_numeric($route) ? $defined : $route) . $this->_params2string($preparedParams) . '.html';
            }
        }
        if ($searchDefined) {
            return $this->_createURL($base, $controller, $action, $params, false);
        }

    }
788476
public function post(string $uri, $action): self
    {
        $this->routes['POST'][$this->trimTrailingSlashes($uri)] = $action;

        return $this;
    }
1289545
private function _getRoute( $controller_name, $action_name )
    {
        $_route = $this->_createRoute( $controller_name, $action_name );

        foreach( $this->_routes as $route )
        {
            if ( $route->getControllerName() == $_route->getControllerName() && $route->getActionName() == $_route->getActionName() )
            {
                return $route;
            }
        }
    }
1318730
protected function handle(string $path, callable $action, $method, string $name = null): HttpRoute
    {
        if (!is_array($method)) {
            $method = [$method];
        }
        /** @var HttpRoute $route */
        $route = $this->data->createRoute($this->prefix . $path, $action, $name);
        $route->method(...$method);
        return $route;
    }
968703
public function all($uri, $action = null)
    {
        $verbs = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'];

        return $this->addRoute($verbs, $uri, $action);
    }
207447
public function any($methods, $uri, $action = null)
    {
        return $this->addRoute(array_map('strtoupper', (array)$methods), $uri, $action);
    }
94729
public function addRoute(array $method, string $uri, $action): Route {
        if (is_string($action)) {
            $action = $this->addPackage($action);
        }
        $uri = $this->addPrefix($uri);
        $route = new Route($uri, is_callable($action) ? $action : function() use ($action) {
            return $this->makeResponse($action);
        }, $method, $this->globalFilters);
        foreach ($route->getMethods() as $item) {
            $this->staticRouteMap[$item][$uri] = $route;
        }
        return $route;
    }
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;
    }