SetCookie
in package
Set-Cookie object
Table of Contents
- $data : array<string|int, mixed>
- $defaults : array<string|int, mixed>
- __construct() : mixed
- __toString() : mixed
- fromString() : self
- Create a new SetCookie object from a string.
- getDiscard() : bool|null
- Get whether or not this is a session cookie.
- getDomain() : string|null
- Get the domain.
- getExpires() : string|int|null
- The UNIX timestamp when the cookie Expires.
- getHttpOnly() : bool
- Get whether or not this is an HTTP only cookie.
- getMaxAge() : int|null
- Maximum lifetime of the cookie in seconds.
- getName() : string
- Get the cookie name.
- getPath() : string
- Get the path.
- getSecure() : bool
- Get whether or not this is a secure cookie.
- getValue() : string|null
- Get the cookie value.
- isExpired() : bool
- Check if the cookie is expired.
- matchesDomain() : bool
- Check if the cookie matches a domain value.
- matchesPath() : bool
- Check if the cookie matches a path value.
- setDiscard() : void
- Set whether or not this is a session cookie.
- setDomain() : void
- Set the domain of the cookie.
- setExpires() : void
- Set the unix timestamp for which the cookie will expire.
- setHttpOnly() : void
- Set whether or not this is an HTTP only cookie.
- setMaxAge() : void
- Set the max-age of the cookie.
- setName() : void
- Set the cookie name.
- setPath() : void
- Set the path of the cookie.
- setSecure() : void
- Set whether or not the cookie is secure.
- setValue() : void
- Set the cookie value.
- toArray() : array<string|int, mixed>
- validate() : bool|string
- Check if the cookie is valid according to RFC 6265.
Properties
$data
private
array<string|int, mixed>
$data
Cookie data
$defaults
private
static array<string|int, mixed>
$defaults
= ['Name' => null, 'Value' => null, 'Domain' => null, 'Path' => '/', 'Max-Age' => null, 'Expires' => null, 'Secure' => false, 'Discard' => false, 'HttpOnly' => false]
Methods
__construct()
public
__construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string|int, mixed> = []
-
Array of cookie data provided by a Cookie parser
Return values
mixed —__toString()
public
__toString() : mixed
Return values
mixed —fromString()
Create a new SetCookie object from a string.
public
static fromString(string $cookie) : self
Parameters
- $cookie : string
-
Set-Cookie header string
Return values
self —getDiscard()
Get whether or not this is a session cookie.
public
getDiscard() : bool|null
Return values
bool|null —getDomain()
Get the domain.
public
getDomain() : string|null
Return values
string|null —getExpires()
The UNIX timestamp when the cookie Expires.
public
getExpires() : string|int|null
Return values
string|int|null —getHttpOnly()
Get whether or not this is an HTTP only cookie.
public
getHttpOnly() : bool
Return values
bool —getMaxAge()
Maximum lifetime of the cookie in seconds.
public
getMaxAge() : int|null
Return values
int|null —getName()
Get the cookie name.
public
getName() : string
Return values
string —getPath()
Get the path.
public
getPath() : string
Return values
string —getSecure()
Get whether or not this is a secure cookie.
public
getSecure() : bool
Return values
bool —getValue()
Get the cookie value.
public
getValue() : string|null
Return values
string|null —isExpired()
Check if the cookie is expired.
public
isExpired() : bool
Return values
bool —matchesDomain()
Check if the cookie matches a domain value.
public
matchesDomain(string $domain) : bool
Parameters
- $domain : string
-
Domain to check against
Return values
bool —matchesPath()
Check if the cookie matches a path value.
public
matchesPath(string $requestPath) : bool
A request-path path-matches a given cookie-path if at least one of the following conditions holds:
- The cookie-path and the request-path are identical.
- The cookie-path is a prefix of the request-path, and the last character of the cookie-path is %x2F ("/").
- The cookie-path is a prefix of the request-path, and the first character of the request-path that is not included in the cookie- path is a %x2F ("/") character.
Parameters
- $requestPath : string
-
Path to check against
Return values
bool —setDiscard()
Set whether or not this is a session cookie.
public
setDiscard(bool $discard) : void
Parameters
- $discard : bool
-
Set to true or false if this is a session cookie
Return values
void —setDomain()
Set the domain of the cookie.
public
setDomain(string|null $domain) : void
Parameters
- $domain : string|null
Return values
void —setExpires()
Set the unix timestamp for which the cookie will expire.
public
setExpires(int|string|null $timestamp) : void
Parameters
- $timestamp : int|string|null
-
Unix timestamp or any English textual datetime description.
Return values
void —setHttpOnly()
Set whether or not this is an HTTP only cookie.
public
setHttpOnly(bool $httpOnly) : void
Parameters
- $httpOnly : bool
-
Set to true or false if this is HTTP only
Return values
void —setMaxAge()
Set the max-age of the cookie.
public
setMaxAge(int|null $maxAge) : void
Parameters
- $maxAge : int|null
-
Max age of the cookie in seconds
Return values
void —setName()
Set the cookie name.
public
setName(string $name) : void
Parameters
- $name : string
-
Cookie name
Return values
void —setPath()
Set the path of the cookie.
public
setPath(string $path) : void
Parameters
- $path : string
-
Path of the cookie
Return values
void —setSecure()
Set whether or not the cookie is secure.
public
setSecure(bool $secure) : void
Parameters
- $secure : bool
-
Set to true or false if secure
Return values
void —setValue()
Set the cookie value.
public
setValue(string $value) : void
Parameters
- $value : string
-
Cookie value
Return values
void —toArray()
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —validate()
Check if the cookie is valid according to RFC 6265.
public
validate() : bool|string
Return values
bool|string —Returns true if valid or an error message if invalid