1.2.5. Cookies

The Response retains each cookie as a Sapien\Response\Cookie value object.

1.2.5.1. Setting

1.2.5.1.1. Setting One Encoded Cookie

final public setCookie(
    string $name,
    string $value = '',
    int $expires = null,
    string $path = null,
    string $domain = null,
    bool $secure = null,
    bool $httponly = null,
    string $samesite = null
) : static

A buffered equivalent of setcookie(), with the various options expanded out to method parameters.

The method is fluent, allowing you to chain a call to another Response method.

1.2.5.1.2. Setting One Raw Cookie

final public setRawCookie(
    string $name,
    string $value = '',
    int $expires = null,
    string $path = null,
    string $domain = null,
    bool $secure = null,
    bool $httponly = null,
    string $samesite = null
) : static

A buffered equivalent of setrawcookie(), with the various options expanded out to method parameters.

The method is fluent, allowing you to chain a call to another Response method.

1.2.5.1.3. Setting One Cookie Instance

final public setCookie(
    string $name,
    Cookie $value
) : static

If you have a Cookie instance in hand, you may set it into the Reponse using setCookie().

The method is fluent, allowing you to chain a call to another Response method.

1.2.5.1.4. Setting All Cookies

final public setCookies(array $cookies) : static

Resets the Response cookies to the key-value pairs of $cookies. The value may be a string, in which case the value will be encoded, or it may be a Cookie instance, in which case it will be retained as-is.

The method is fluent, allowing you to chain a call to another Response method.

1.2.5.2. Getting

1.2.5.2.1. Getting One Cookie

final public getCookie(string $name) : ?Cookie

Returns the $name Cookie from the Response.

1.2.5.2.2. Getting All Cookies

final public getCookies() : array

Returns the array of Cookie objects in the Response.

1.2.5.3. Checking

final public hasCookie(string $name) : bool

Returns true if the $name Cookie exists in the Response, false if not.

1.2.5.4. Removing

1.2.5.4.1. Removing One Cookie

final public unsetCookie(string $name) : static

Removes the $name Cookie from the Response.

The method is fluent, allowing you to chain a call to another Response method.

1.2.5.4.2. Removing All Cookies

final public unsetCookies() : static

Removes all Cookie objects from the Response.

The method is fluent, allowing you to chain a call to another Response method.