public function sendCookie(string $name, ?string $value, int $expire = 0,
        string $path = '/', string $domain = '', bool $secure = false, bool $httpOnly = false): void
    {
        // check name
        if (!preg_match('~^[a-z0-9_\-\.]+$~i', $name)) {
            throw new HttpException("Invalid cookie name '{$name}' given");
        }

        $value = (string) $value;
        if ($expire < 0) {
            $value = '';
        }

        setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
    }