Constants

EXPIRES_FORMAT

EXPIRES_FORMAT = 'D, d-M-Y H:i:s T' : string

Expires attribute format.

Methods

withName()

withName(string  $name) : static

Sets the cookie name

Parameters

string $name

Name of the cookie

Returns

static

getName()

getName() : string

Gets the cookie name

Returns

string

getValue()

getValue() : string|array

Gets the cookie value

Returns

string|array

getStringValue()

getStringValue() : string

Gets the cookie value as a string.

This will collapse any complex data in the cookie with json_encode()

Returns

string

withValue()

withValue(string|array  $value) : static

Create a cookie with an updated value.

Parameters

string|array $value

Value of the cookie to set

Returns

static

getId()

getId() : string

Get the id for a cookie

Cookies are unique across name, domain, path tuples.

Returns

string

getPath()

getPath() : string

Get the path attribute.

Returns

string

withPath()

withPath(string  $path) : static

Create a new cookie with an updated path

Parameters

string $path

Sets the path

Returns

static

getDomain()

getDomain() : string

Get the domain attribute.

Returns

string

withDomain()

withDomain(string  $domain) : static

Create a cookie with an updated domain

Parameters

string $domain

Domain to set

Returns

static

getExpiry()

getExpiry() : \DateTime|\DateTimeImmutable|null

Get the current expiry time

Returns

\DateTime|\DateTimeImmutable|null —

Timestamp of expiry or null

getExpiresTimestamp()

getExpiresTimestamp() : string|null

Get the timestamp from the expiration time

Timestamps are strings as large timestamps can overflow MAX_INT in 32bit systems.

Returns

string|null —

The expiry time as a string timestamp.

getFormattedExpires()

getFormattedExpires() : string

Builds the expiration value part of the header string

Returns

string

withExpiry()

withExpiry(\DateTime|\DateTimeImmutable  $dateTime) : static

Create a cookie with an updated expiration date

Parameters

\DateTime|\DateTimeImmutable $dateTime

Date time object

Returns

static

withNeverExpire()

withNeverExpire() : static

Create a new cookie that will virtually never expire.

Returns

static

withExpired()

withExpired() : static

Create a new cookie that will expire/delete the cookie from the browser.

This is done by setting the expiration time to 1 year ago

Returns

static

isExpired()

isExpired(\DateTime|\DateTimeImmutable  $time = null) : boolean

Check if a cookie is expired when compared to $time

Cookies without an expiration date always return false.

Parameters

\DateTime|\DateTimeImmutable $time

The time to test against. Defaults to 'now' in UTC.

Returns

boolean

isHttpOnly()

isHttpOnly() : boolean

Check if the cookie is HTTP only

Returns

boolean

withHttpOnly()

withHttpOnly(boolean  $httpOnly) : static

Create a cookie with HTTP Only updated

Parameters

boolean $httpOnly

HTTP Only

Returns

static

isSecure()

isSecure() : boolean

Check if the cookie is secure

Returns

boolean

withSecure()

withSecure(boolean  $secure) : static

Create a cookie with Secure updated

Parameters

boolean $secure

Secure attribute value

Returns

static

toHeaderValue()

toHeaderValue() : string

Returns the cookie as header value

Returns

string