Cookie
in package
Represents a cookie.
Tags
Table of Contents
- SAMESITE_LAX = 'lax'
- SAMESITE_NONE = 'none'
- SAMESITE_STRICT = 'strict'
- RESERVED_CHARS_FROM = ['=', ',', ';', ' ', " ", " ", " ", "", ""]
- RESERVED_CHARS_LIST = "=,; "
- RESERVED_CHARS_TO = ['%3D', '%2C', '%3B', '%20', '%09', '%0D', '%0A', '%0B', '%0C']
- $domain : mixed
- $expire : mixed
- $httpOnly : mixed
- $name : mixed
- $path : mixed
- $secure : mixed
- $value : mixed
- $raw : mixed
- $sameSite : mixed
- $secureDefault : mixed
- __construct() : mixed
- __toString() : string
- Returns the cookie as a string.
- create() : self
- fromString() : static
- Creates cookie from raw header string.
- getDomain() : string|null
- Gets the domain that the cookie is available to.
- getExpiresTime() : int
- Gets the time the cookie expires.
- getMaxAge() : int
- Gets the max-age attribute.
- getName() : string
- Gets the name of the cookie.
- getPath() : string
- Gets the path on the server in which the cookie will be available on.
- getSameSite() : string|null
- Gets the SameSite attribute.
- getValue() : string|null
- Gets the value of the cookie.
- isCleared() : bool
- Whether this cookie is about to be cleared.
- isHttpOnly() : bool
- Checks whether the cookie will be made accessible only through the HTTP protocol.
- isRaw() : bool
- Checks if the cookie value should be sent with no url encoding.
- isSecure() : bool
- Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client.
- setSecureDefault() : void
- withDomain() : static
- Creates a cookie copy with a new domain that the cookie is available to.
- withExpires() : static
- Creates a cookie copy with a new time the cookie expires.
- withHttpOnly() : static
- Creates a cookie copy that be accessible only through the HTTP protocol.
- withPath() : static
- Creates a cookie copy with a new path on the server in which the cookie will be available on.
- withRaw() : static
- Creates a cookie copy that uses no url encoding.
- withSameSite() : static
- Creates a cookie copy with SameSite attribute.
- withSecure() : static
- Creates a cookie copy that only be transmitted over a secure HTTPS connection from the client.
- withValue() : static
- Creates a cookie copy with a new value.
- expiresTimestamp() : int
- Converts expires formats to a unix timestamp.
Constants
SAMESITE_LAX
public
mixed
SAMESITE_LAX
= 'lax'
SAMESITE_NONE
public
mixed
SAMESITE_NONE
= 'none'
SAMESITE_STRICT
public
mixed
SAMESITE_STRICT
= 'strict'
RESERVED_CHARS_FROM
private
mixed
RESERVED_CHARS_FROM
= ['=', ',', ';', ' ', " ", "
", "
", "", ""]
RESERVED_CHARS_LIST
private
mixed
RESERVED_CHARS_LIST
= "=,;
"
RESERVED_CHARS_TO
private
mixed
RESERVED_CHARS_TO
= ['%3D', '%2C', '%3B', '%20', '%09', '%0D', '%0A', '%0B', '%0C']
Properties
$domain
protected
mixed
$domain
$expire
protected
mixed
$expire
$httpOnly
protected
mixed
$httpOnly
$name
protected
mixed
$name
$path
protected
mixed
$path
$secure
protected
mixed
$secure
$value
protected
mixed
$value
$raw
private
mixed
$raw
$sameSite
private
mixed
$sameSite
$secureDefault
private
mixed
$secureDefault
= false
Methods
__construct()
public
__construct(string $name[, string|null $value = null ], int|string|DateTimeInterface $expire[, string|null $path = '/' ][, string|null $domain = null ][, bool|null $secure = null ][, bool $httpOnly = true ][, bool $raw = false ][, string|null $sameSite = 'lax' ]) : mixed
Parameters
- $name : string
-
The name of the cookie
- $value : string|null = null
-
The value of the cookie
- $expire : int|string|DateTimeInterface
-
The time the cookie expires
- $path : string|null = '/'
-
The path on the server in which the cookie will be available on
- $domain : string|null = null
-
The domain that the cookie is available to
- $secure : bool|null = null
-
Whether the client should send back the cookie only over HTTPS or null to auto-enable this when the request is already using HTTPS
- $httpOnly : bool = true
-
Whether the cookie will be made accessible only through the HTTP protocol
- $raw : bool = false
-
Whether the cookie value should be sent with no url encoding
- $sameSite : string|null = 'lax'
-
Whether the cookie will be available for cross-site requests
Tags
Return values
mixed —__toString()
Returns the cookie as a string.
public
__toString() : string
Return values
string —create()
public
static create(string $name[, string|null $value = null ], mixed $expire[, string|null $path = '/' ][, string|null $domain = null ][, bool|null $secure = null ][, bool $httpOnly = true ][, bool $raw = false ][, string|null $sameSite = self::SAMESITE_LAX ]) : self
Parameters
- $name : string
- $value : string|null = null
- $expire : mixed
- $path : string|null = '/'
- $domain : string|null = null
- $secure : bool|null = null
- $httpOnly : bool = true
- $raw : bool = false
- $sameSite : string|null = self::SAMESITE_LAX
Return values
self —fromString()
Creates cookie from raw header string.
public
static fromString(string $cookie[, bool $decode = false ]) : static
Parameters
- $cookie : string
- $decode : bool = false
Return values
static —getDomain()
Gets the domain that the cookie is available to.
public
getDomain() : string|null
Return values
string|null —getExpiresTime()
Gets the time the cookie expires.
public
getExpiresTime() : int
Return values
int —getMaxAge()
Gets the max-age attribute.
public
getMaxAge() : int
Return values
int —getName()
Gets the name of the cookie.
public
getName() : string
Return values
string —getPath()
Gets the path on the server in which the cookie will be available on.
public
getPath() : string
Return values
string —getSameSite()
Gets the SameSite attribute.
public
getSameSite() : string|null
Return values
string|null —getValue()
Gets the value of the cookie.
public
getValue() : string|null
Return values
string|null —isCleared()
Whether this cookie is about to be cleared.
public
isCleared() : bool
Return values
bool —isHttpOnly()
Checks whether the cookie will be made accessible only through the HTTP protocol.
public
isHttpOnly() : bool
Return values
bool —isRaw()
Checks if the cookie value should be sent with no url encoding.
public
isRaw() : bool
Return values
bool —isSecure()
Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client.
public
isSecure() : bool
Return values
bool —setSecureDefault()
public
setSecureDefault(bool $default) : void
Parameters
- $default : bool
-
The default value of the "secure" flag when it is set to null
Return values
void —withDomain()
Creates a cookie copy with a new domain that the cookie is available to.
public
withDomain(string|null $domain) : static
Parameters
- $domain : string|null
Return values
static —withExpires()
Creates a cookie copy with a new time the cookie expires.
public
withExpires(int|string|DateTimeInterface $expire) : static
Parameters
- $expire : int|string|DateTimeInterface
Return values
static —withHttpOnly()
Creates a cookie copy that be accessible only through the HTTP protocol.
public
withHttpOnly([bool $httpOnly = true ]) : static
Parameters
- $httpOnly : bool = true
Return values
static —withPath()
Creates a cookie copy with a new path on the server in which the cookie will be available on.
public
withPath(string $path) : static
Parameters
- $path : string
Return values
static —withRaw()
Creates a cookie copy that uses no url encoding.
public
withRaw([bool $raw = true ]) : static
Parameters
- $raw : bool = true
Return values
static —withSameSite()
Creates a cookie copy with SameSite attribute.
public
withSameSite(string|null $sameSite) : static
Parameters
- $sameSite : string|null
Return values
static —withSecure()
Creates a cookie copy that only be transmitted over a secure HTTPS connection from the client.
public
withSecure([bool $secure = true ]) : static
Parameters
- $secure : bool = true
Return values
static —withValue()
Creates a cookie copy with a new value.
public
withValue(string|null $value) : static
Parameters
- $value : string|null
Return values
static —expiresTimestamp()
Converts expires formats to a unix timestamp.
private
static expiresTimestamp(int|string|DateTimeInterface $expire) : int
Parameters
- $expire : int|string|DateTimeInterface