Added ability to remove cookies.
This commit is contained in:
parent
b67f5c8e90
commit
884d2cb9da
1 changed files with 15 additions and 1 deletions
|
@ -61,7 +61,10 @@ class HttpResponseBuilder extends HttpMessageBuilder {
|
|||
$expires = DateTime::createFromInterface($expires);
|
||||
}
|
||||
|
||||
$maxAge = $expires->difference(DateTime::now())->totalSeconds();
|
||||
$now = DateTime::now();
|
||||
$maxAge = $expires->isLessThanOrEqual($now)
|
||||
? -1 : $expires->difference($now)->totalSeconds();
|
||||
|
||||
$expires = $expires->toCookieString();
|
||||
$cookie .= '; Expires=' . $expires . '; Max-Age=' . $maxAge;
|
||||
}
|
||||
|
@ -81,6 +84,17 @@ class HttpResponseBuilder extends HttpMessageBuilder {
|
|||
$this->addHeader('Set-Cookie', $cookie);
|
||||
}
|
||||
|
||||
public function removeCookie(
|
||||
string $name,
|
||||
string $path = '',
|
||||
string $domain = '',
|
||||
bool $secure = false,
|
||||
bool $httpOnly = false,
|
||||
bool $sameSiteStrict = false
|
||||
): void {
|
||||
$this->addCookie($name, '', -9001, $path, $domain, $secure, $httpOnly, $sameSiteStrict);
|
||||
}
|
||||
|
||||
public function redirect(string $to, bool $permanent = false): void {
|
||||
$this->setStatusCode($permanent ? 301 : 302);
|
||||
$this->setHeader('Location', $to);
|
||||
|
|
Loading…
Reference in a new issue