Routes Group

@param string $name
@param closure|array $settings
@param null|closure $callback

@return bool
338527
public function group($name, $settings = null, $callback = null)
    {
        if($this->cacheLoaded) {
            return true;
        }

        $groupName = trim($name, '/');
        $group = [];
        $group['route'] = '/' . $groupName;
        $group['before'] = $group['after'] = null;

        if (is_null($callback)) {
            $callback = $settings;
        } else {
            $group['before'][] = (!isset($settings['before']) ? null : $settings['before']);
            $group['after'][]  = (!isset($settings['after']) ? null : $settings['after']);
        }

        $groupCount = count($this->groups);
        if ($groupCount > 0) {
            $list = [];
            foreach ($this->groups as $key => $value) {
                if (is_array($value['before'])) {
                    foreach ($value['before'] as $k => $v) {
                        $list['before'][] = $v;
                    }
                    foreach ($value['after'] as $k => $v) {
                        $list['after'][] = $v;
                    }
                }
            }

            if (! is_null($group['before'])) {
                $list['before'][] = $group['before'][0];
            }

            if (! is_null($group['after'])) {
                $list['after'][] = $group['after'][0];
            }

            $group['before'] = $list['before'];
            $group['after'] = $list['after'];
        }

        $group['before'] = array_values(array_unique( (array) $group['before']));
        $group['after'] = array_values(array_unique( (array) $group['after']));

        array_push($this->groups, $group);

        if (is_object($callback)) {
            call_user_func_array($callback, [$this]);
        }

        $this->endGroup();

        return true;
    }
387143
public function group(array $routeOption = [], $callback)
    {
        if (isset($routeOption['namespace'])) {
            $this->namespace = '\\' . $routeOption['namespace'] . '\\';
        }

        (isset($routeOption['prefix'])) ? $this->prefix = '/' . $routeOption['prefix'] : $this->prefix = '';

        (isset($routeOption['filter'])) ? $this->filter = ['filter' => $routeOption['filter']] : $this->filter = [];

        call_user_func_array($callback, $routeOption);

        $this->prefix = '';

        $this->filter = [];
    }
1061186
public function any(string $name, ?string $pattern = null, array $options = []): RouteData
    {
        $groups = $this->groups;

        $route = new RouteData($name);

        $this->routes[implode('.', array_keys($groups)) . '@' . $name] = $route;

        $route->setOptions($options);

        if ($pattern) {
            $pattern = '/' . ltrim($pattern, '/');

            $route->pattern($pattern);
        }

        // Middlewares
        $middlewares = array_filter(array_column($groups, 'middlewares'), 'is_array');

        if ($middlewares !== []) {
            $middlewares = array_merge(...$middlewares);

            $route->middlewares($middlewares);
        }

        $route->groups($this->groups)
            ->package((string) $this->getOption('package'));

        return $route;
    }
875409
public function macro($name, Closure $callback){
        $this->macros[$name] = Closure::bind($callback, $this, get_class());

        return $this;
    }
495743
public function add($methods, $route, $settings, $callback = null)
    {
        if($this->cacheLoaded) {
            return true;
        }

        if (is_null($callback)) {
            $callback = $settings;
            $settings = null;
        }

        if (strstr($methods, '|')) {
            foreach (array_unique(explode('|', $methods)) as $method) {
                if ($method != '') {
                    call_user_func_array([$this, strtolower($method)], [$route, $settings, $callback]);
                }
            }
        } else {
            call_user_func_array([$this, strtolower($methods)], [$route, $settings, $callback]);
        }

        return true;
    }
1273360
private function getGroupByName($name)
    {
        foreach (Craft::$app->sites->getAllGroups() as $group) {
            if ($group->name === $name) {
                return $group;
            }
        }
        return null;
    }
1059764
public function group(array $attributes, Closure $callback)
    {
        $parentGroupAttributes = $this->groupAttributes;

        $prefix = (isset($this->groupAttributes['prefix']) ? $this->groupAttributes['prefix'] : '').'/'.
            (isset($attributes['prefix']) ? $attributes['prefix'] : '');

        $middleware = (isset($this->groupAttributes['middleware']) ? $this->groupAttributes['middleware'] : '').'|'.
            (isset($attributes['middleware']) ? $attributes['middleware'] : '');

        $namespace = (isset($this->groupAttributes['namespace']) ? $this->groupAttributes['namespace'] : '').'\\'.
            (isset($attributes['namespace']) ? $attributes['namespace'] : '');

        $this->groupAttributes = [
            'prefix' => $prefix,
            'middleware' => $middleware,
            'namespace' => $namespace
        ];

        call_user_func($callback, $this);

        $this->groupAttributes = $parentGroupAttributes;
    }
929050
public function group(array $attributes, Closure $callback)
    {
        $previousGroupAttributes = $this->groupAttributes;
        $this->groupAttributes = array_merge_recursive($previousGroupAttributes, $attributes);

        \call_user_func($callback, $this);

        $this->groupAttributes = $previousGroupAttributes;
    }
438242
protected function createRoute(array $methods, string $name, string $path, $target, array $matchers = []) : Route
    {
        $builder = RouteBuilder::route($this->defaultRouteClass);

        $builder->from($path)->to($target);

        foreach ($methods as $method) {
            $builder->accepting($method);
        }

        $builder->named($name);

        foreach ($matchers as $param => $paramMatchers) {
            foreach ($paramMatchers as $matcher) {
                $builder->ifMatches($param, $matcher);
            }
        }

        return $builder->build();
    }
194171
public function department($name, Closure $callback)
    {
        $department = $this->createDepartment($name);

        call_user_func($callback, $department);

        if (is_null(static::$departments)) {
            static::$departments = Collection::make([]);
        }

        static::$departments->push($department);

        return $this;
    }
502104
public function group(string $prefix, callable $callback): RouteGroup
    {
        $prefix = ($prefix === '/') ? $this->prefix : rtrim($this->prefix, '/') . sprintf('/%s', ltrim($prefix, '/'));

        $group = $this->router->group($prefix, $callback);

        // in cases of group of groups, we need to persist the settings from the previous group in the new one.
        if ($host = $this->getHost()) {
            $group->setHost($host);
        }
        if ($scheme = $this->getScheme()) {
            $group->setScheme($scheme);
        }
        if ($port = $this->getPort()) {
            $group->setPort($port);
        }
        if ($strategy = $this->getStrategy()) {
            $group->setStrategy($strategy);
        }

        // merge all the previous group middlewares in this last group.
        $group->middleware(array_merge($this->getMiddlewareStack(), $group->getMiddlewareStack()));

        return $group;
    }
162006
public function group(string $groupName, \Closure $callback) {
        $this->currentGroupName = $groupName;

        $this->isGroupe = TRUE;
        $this->isGroupeMiddlewares = FALSE;
        $callback($this);
        $this->isGroupeMiddlewares = TRUE;
        $this->currentGroupName = NULL;

        return $this;
    }
887874
public function group($name, $route, array $option = [], array $pattern = [])
    {
        if (is_array($name)) {
            $option = $name;
            $name = isset($option['name']) ? $option['name'] : '';
        }

        return (new RuleGroup($this, $this->group, $name, $route, $option, $pattern))
            ->lazy($this->lazy)
            ->mergeRuleRegex($this->mergeRuleRegex);
    }
1182853
public function group($name, \Closure $callback = null)
    {
        $group = $this->getGroup($name);

        if ($callback) {
            $this->startGroup($name);
            call_user_func_array($callback, [$this, $group]);
            $this->stopGroup($name);

            return $group;
        } else {
            $this->startGroup($name);
            $this->events->once('after-add-field', __METHOD__ . $name, function () use ($name) {
                $this->stopGroup($name);
            });

            return $this;
        }
    }
1169138
public function addRoute(
        string $name,
        array $methods,
        string $pattern,
        array $middlewares,
        array $handler,
        string $group = null
    ) {
        $this->routes[$name] = [
            'methods' => $methods,
            'pattern' => $pattern,
            'middlewares' => $middlewares,
            'handler' => $handler,
            'group' => $group
        ];
    }
1370114
public function modify($name, Closure $callback)
    {
        $menu = collect($this->menus)->filter(function ($menu) use ($name) {
            return $menu->getName() == $name;
        })->first();

        $callback($menu);
    }
384900
public function group(string $prefix, \Closure $callback, array $opts = [])
    {
        $previousGroupPrefix = $this->currentGroupPrefix;
        $this->currentGroupPrefix = $previousGroupPrefix . '/' . \trim($prefix, '/');

        $previousGroupOption = $this->currentGroupOption;
        $this->currentGroupOption = $opts;

        $callback($this);

        $this->currentGroupPrefix = $previousGroupPrefix;
        $this->currentGroupOption = $previousGroupOption;
    }