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() publicGet the domain attribute. 
- 
          getExpiresTimestamp() publicGet the timestamp from the expiration time 
- 
          getExpiry() publicGet the current expiry time 
- 
          getFormattedExpires() publicBuilds the expiration value part of the header string 
- 
          getId() publicGet the id for a cookie 
- 
          getName() publicGets the cookie name 
- 
          getOptions() publicGet cookie options 
- 
          getPath() publicGet the path attribute. 
- 
          getSameSite() publicGet the SameSite attribute. 
- 
          getScalarValue() publicGets the cookie value as scalar. 
- 
          getValue() publicGets the cookie value 
- 
          isExpired() publicCheck if a cookie is expired when compared to $time 
- 
          isHttpOnly() publicCheck if the cookie is HTTP only 
- 
          isSecure() publicCheck if the cookie is secure 
- 
          toArray() publicGet cookie data as array. 
- 
          toHeaderValue() publicReturns the cookie as header value 
- 
          withDomain() publicCreate a cookie with an updated domain 
- 
          withExpired() publicCreate a new cookie that will expire/delete the cookie from the browser. 
- 
          withExpiry() publicCreate a cookie with an updated expiration date 
- 
          withHttpOnly() publicCreate a cookie with HTTP Only updated 
- 
          withName() publicSets the cookie name 
- 
          withNeverExpire() publicCreate a new cookie that will virtually never expire. 
- 
          withPath() publicCreate a new cookie with an updated path 
- 
          withSameSite() publicCreate a cookie with an updated SameSite option. 
- 
          withSecure() publicCreate a cookie with Secure updated 
- 
          withValue() publicCreate a cookie with an updated value. 
Method Detail
getExpiresTimestamp() ¶ public
getExpiresTimestamp(): int|nullGet the timestamp from the expiration time
Returns
int|nullThe expiry time as an integer.
getExpiry() ¶ public
getExpiry(): DateTime|DateTimeImmutable|nullGet the current expiry time
Returns
DateTime|DateTimeImmutable|nullTimestamp of expiry or null
getFormattedExpires() ¶ public
getFormattedExpires(): stringBuilds the expiration value part of the header string
Returns
stringgetId() ¶ public
getId(): stringGet the id for a cookie
Cookies are unique across name, domain, path tuples.
Returns
stringgetOptions() ¶ public
getOptions(): array<string, mixed>Get cookie options
Returns
array<string, mixed>getScalarValue() ¶ public
getScalarValue(): mixedGets the cookie value as scalar.
This will collapse any complex data in the cookie with json_encode()
Returns
mixedisExpired() ¶ public
isExpired(DateTime|DateTimeImmutable $time = null): boolCheck if a cookie is expired when compared to $time
Cookies without an expiration date always return false.
Parameters
- 
                DateTime|DateTimeImmutable$time optional
- The time to test against. Defaults to 'now' in UTC. 
Returns
booltoArray() ¶ public
toArray(): array<string, mixed>Get cookie data as array.
Returns
array<string, mixed>With keys name, value, expires etc. options.
withDomain() ¶ public
withDomain(string $domain): staticCreate a cookie with an updated domain
Parameters
- 
                string$domain
- Domain to set 
Returns
staticwithExpired() ¶ public
withExpired(): staticCreate 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(DateTime|DateTimeImmutable $dateTime): staticCreate a cookie with an updated expiration date
Parameters
- 
                DateTime|DateTimeImmutable$dateTime
- Date time object 
Returns
staticwithHttpOnly() ¶ public
withHttpOnly(bool $httpOnly): staticCreate a cookie with HTTP Only updated
Parameters
- 
                bool$httpOnly
- HTTP Only 
Returns
staticwithName() ¶ public
withName(string $name): staticSets the cookie name
Parameters
- 
                string$name
- Name of the cookie 
Returns
staticwithNeverExpire() ¶ public
withNeverExpire(): staticCreate a new cookie that will virtually never expire.
Returns
staticwithPath() ¶ public
withPath(string $path): staticCreate a new cookie with an updated path
Parameters
- 
                string$path
- Sets the path 
Returns
staticwithSameSite() ¶ public
withSameSite(string|null $sameSite): staticCreate 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): staticCreate a cookie with Secure updated
Parameters
- 
                bool$secure
- Secure attribute value 
Returns
staticwithValue() ¶ public
withValue(array|string $value): staticCreate a cookie with an updated value.
Parameters
- 
                array|string$value
- Value of the cookie to set 
Returns
static