withHeader($name, $value); }); } /** * Remove current response header * @param string $name Case-insensitive header field name to remove. * @return \bff\http\Response */ public static function withoutHeader($name) { return static::current(function (\bff\http\Response $response) use ($name) { return $response->withoutHeader($name); }); } /** * Set current response cookie * @param string $name The name of the cookie * @param string|null $value The value of the cookie * @param int|string|\DateTimeInterface $expire The time the cookie expires: '+7 days' or 7 (days) * @param array $options Additional options: path, domain, secure, http_only, raw, same_site, encrypt * @return \bff\http\Response */ public static function setCookie(string $name, ?string $value = null, $expire = 0, array $options = []) { if (is_int($expire) && $expire > 0 && $expire <= 1000) { $expire = '+' . $expire . ' days'; } $cookie = new Cookie( $name, (! empty($options['encrypt']) ? Crypt::encryptString($value) : $value), $expire, $options['path'] ?? '/', # The path on the server in which the cookie will be available on $options['domain'] ?? null, # The domain that the cookie is available to $options['secure'] ?? null, # Whether the client should send back the cookie only over HTTPS or null to auto-enable this when the request is already using HTTPS $options['http_only'] ?? true, # Whether the cookie will be made accessible only through the HTTP protocol $options['raw'] ?? false, # Whether the cookie value should be sent with no url encoding $options['same_site'] ?? Cookie::SAMESITE_LAX # Whether the cookie will be available for cross-site requests ); return static::current(function (\bff\http\Response $response) use ($cookie) { return $response->withCookie($cookie); }); } /** * Set current response encrypted cookie * @param string $name The name of the cookie * @param string|null $value The value of the cookie * @param int|string|\DateTimeInterface $expire The time the cookie expires: '+7 days' or 7 (days) * @param array $options Additional options: path, domain, secure, http_only, raw, same_site * @return \bff\http\Response */ public static function setEncryptedCookie(string $name, ?string $value = null, $expire = 0, array $options = []) { $options['encrypt'] = true; return static::setCookie($name, $value, $expire, $options); } /** * Delete current response cookie * @param string $name * @param string|null $path * @param string|null $domain * @param bool $secure * @param bool $httpOnly * @param string|null $sameSite * @return \bff\http\Response */ public static function deleteCookie(string $name, ?string $path = '/', ?string $domain = null, bool $secure = false, bool $httpOnly = true, string $sameSite = null) { return static::current(function (\bff\http\Response $response) use ($name, $path, $domain, $secure, $httpOnly, $sameSite) { return $response->deleteCookie($name, $path, $domain, $secure, $httpOnly, $sameSite); }); } protected static function getFacadeAccessor() { return ResponseFactory::class; } }