protected function groupMiddleware(string $name = null, Closure $closure = null)
    {
        if ($name === null) {
            return $this->middlewareGroupId;
        } else {
            $previousGroup = $this->middlewareGroupId;
            $this->middlewareGroupId = $name;
            if ($closure !== null) {
                $closure($this);
                $this->middlewareGroupId = $previousGroup;
            }
            return $this;
        }
    }