Interface CookieInterface
Cookie Interface
Constants
-
stringEXPIRES_FORMAT'D, d-M-Y H:i:s T'
Expires attribute format.
-
stringSAMESITE_LAX'Lax'
SameSite attribute value: Lax
-
stringSAMESITE_NONE'None'
SameSite attribute value: None
-
stringSAMESITE_STRICT'Strict'
SameSite attribute value: Strict
-
array<string>SAMESITE_VALUES[self::SAMESITE_LAX, self::SAMESITE_STRICT, self::SAMESITE_NONE]
Valid values for "SameSite" attribute.
Method Summary
-
getDomain() public
Get the domain attribute.
-
getExpiresTimestamp() public
Get the timestamp from the expiration time
-
getExpiry() public
Get the current expiry time
-
getFormattedExpires() public
Builds the expiration value part of the header string
-
getId() public
Get the id for a cookie
-
getName() public
Gets the cookie name
-
getOptions() public
Get cookie options
-
getPath() public
Get the path attribute.
-
getSameSite() public
Get the SameSite attribute.
-
getScalarValue() public
Gets the cookie value as scalar.
-
getValue() public
Gets the cookie value
-
isExpired() public
Check if a cookie is expired when compared to $time
-
isHttpOnly() public
Check if the cookie is HTTP only
-
isSecure() public
Check if the cookie is secure
-
toArray() public
Get cookie data as array.
-
toHeaderValue() public
Returns the cookie as header value
-
withDomain() public
Create a cookie with an updated domain
-
withExpired() public
Create a new cookie that will expire/delete the cookie from the browser.
-
withExpiry() public
Create a cookie with an updated expiration date
-
withHttpOnly() public
Create a cookie with HTTP Only updated
-
withName() public
Sets the cookie name
-
withNeverExpire() public
Create a new cookie that will virtually never expire.
-
withPath() public
Create a new cookie with an updated path
-
withSameSite() public
Create a cookie with an updated SameSite option.
-
withSecure() public
Create a cookie with Secure updated
-
withValue() public
Create a cookie with an updated value.
Method Detail
getDomain() public
getDomain(): string
Get the domain attribute.
Returns
stringgetExpiresTimestamp() public
getExpiresTimestamp(): int|null
Get the timestamp from the expiration time
Returns
int|nullgetExpiry() public
getExpiry(): DateTimeDateTimeImmutable|null
Get the current expiry time
Returns
DateTimeDateTimeImmutable|nullgetFormattedExpires() public
getFormattedExpires(): string
Builds the expiration value part of the header string
Returns
stringgetId() public
getId(): string
Get the id for a cookie
Cookies are unique across name, domain, path tuples.
Returns
stringgetName() public
getName(): string
Gets the cookie name
Returns
stringgetOptions() public
getOptions(): array<string, mixed>
Get cookie options
Returns
array<string, mixed>getPath() public
getPath(): string
Get the path attribute.
Returns
stringgetSameSite() public
getSameSite(): string|null
Get the SameSite attribute.
Returns
string|nullgetScalarValue() public
getScalarValue(): mixed
Gets the cookie value as scalar.
This will collapse any complex data in the cookie with json_encode()
Returns
mixedgetValue() public
getValue(): array|string
Gets the cookie value
Returns
array|stringisExpired() public
isExpired(DateTimeDateTimeImmutable $time = null): bool
Check if a cookie is expired when compared to $time
Cookies without an expiration date always return false.
Parameters
-
DateTimeDateTimeImmutable$time optional The time to test against. Defaults to 'now' in UTC.
Returns
boolisHttpOnly() public
isHttpOnly(): bool
Check if the cookie is HTTP only
Returns
boolisSecure() public
isSecure(): bool
Check if the cookie is secure
Returns
booltoArray() public
toArray(): array<string, mixed>
Get cookie data as array.
Returns
array<string, mixed>toHeaderValue() public
toHeaderValue(): string
Returns the cookie as header value
Returns
stringwithDomain() public
withDomain(string $domain): static
Create a cookie with an updated domain
Parameters
-
string$domain Domain to set
Returns
staticwithExpired() public
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
staticwithExpiry() public
withExpiry(DateTimeDateTimeImmutable $dateTime): static
Create a cookie with an updated expiration date
Parameters
-
DateTimeDateTimeImmutable$dateTime Date time object
Returns
staticwithHttpOnly() public
withHttpOnly(bool $httpOnly): static
Create a cookie with HTTP Only updated
Parameters
-
bool$httpOnly HTTP Only
Returns
staticwithName() public
withName(string $name): static
Sets the cookie name
Parameters
-
string$name Name of the cookie
Returns
staticwithNeverExpire() public
withNeverExpire(): static
Create a new cookie that will virtually never expire.
Returns
staticwithPath() public
withPath(string $path): static
Create a new cookie with an updated path
Parameters
-
string$path Sets the path
Returns
staticwithSameSite() public
withSameSite(string|null $sameSite): static
Create a cookie with an updated SameSite option.
Parameters
-
string|null$sameSite Value for to set for Samesite option. One of CookieInterface::SAMESITE_* constants.
Returns
staticwithSecure() public
withSecure(bool $secure): static
Create a cookie with Secure updated
Parameters
-
bool$secure Secure attribute value
Returns
staticwithValue() public
withValue(array|string $value): static
Create a cookie with an updated value.
Parameters
-
array|string$value Value of the cookie to set
Returns
static
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/interface-Cake.Http.Cookie.CookieInterface.html