Cookie
in package
implements
ToArrayInterface
Set-Cookie object
Table of Contents
Interfaces
- ToArrayInterface
- An object that can be represented as an array
Properties
- $data : array<string|int, mixed>
- $invalidCharString : string
Methods
- __construct() : mixed
- getAttribute() : null|string
- Get a specific data point from the extra cookie data
- getAttributes() : array<string|int, mixed>
- Get an array of extra cookie data
- getComment() : string|null
- Get the comment
- getCommentUrl() : string|null
- Get the comment URL of the cookie
- getDiscard() : null|bool
- Get whether or not this is a session cookie
- getDomain() : string|null
- Get the domain
- getExpires() : mixed
- 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
- getPorts() : array<string|int, mixed>
- Get an array of acceptable ports this cookie can be used with
- getSecure() : null|bool
- Get whether or not this is a secure cookie
- getValue() : string
- Get the cookie value
- getVersion() : mixed
- Version of the cookie specification. RFC 2965 is 1
- 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
- matchesPort() : bool
- Check if the cookie is compatible with a specific port
- setAttribute() : Cookie
- Set a cookie data attribute
- setComment() : Cookie
- Set the comment of the cookie
- setCommentUrl() : Cookie
- Set the comment URL of the cookie
- setDiscard() : Cookie
- Set whether or not this is a session cookie
- setDomain() : Cookie
- Set the domain of the cookie
- setExpires() : Cookie
- Set the unix timestamp for which the cookie will expire
- setHttpOnly() : Cookie
- Set whether or not this is an HTTP only cookie
- setMaxAge() : Cookie
- Set the max-age of the cookie
- setName() : Cookie
- Set the cookie name
- setPath() : Cookie
- Set the path of the cookie
- setPorts() : Cookie
- Set a list of acceptable ports this cookie can be used with
- setSecure() : Cookie
- Set whether or not the cookie is secure
- setValue() : Cookie
- Set the cookie value
- setVersion() : Cookie
- Set the cookie version
- toArray() : array<string|int, mixed>
- Get the cookie as an array
- validate() : bool|string
- Check if the cookie is valid according to RFC 6265
- getInvalidCharacters() : array<string|int, mixed>
- Gets an array of invalid cookie characters
- setData() : Cookie
- Set a value and return the cookie object
Properties
$data
protected
array<string|int, mixed>
$data
Cookie data
$invalidCharString
protected
static string
$invalidCharString
ASCII codes not valid for for use in a cookie name
Cookie names are defined as 'token', according to RFC 2616, Section 2.2 A valid token may contain any CHAR except CTLs (ASCII 0 - 31 or 127) or any of the following separators
Methods
__construct()
public
__construct([array<string|int, mixed> $data = array() ]) : mixed
Parameters
- $data : array<string|int, mixed> = array()
-
Array of cookie data provided by a Cookie parser
getAttribute()
Get a specific data point from the extra cookie data
public
getAttribute(string $name) : null|string
Parameters
- $name : string
-
Name of the data point to retrieve
Return values
null|stringgetAttributes()
Get an array of extra cookie data
public
getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getComment()
Get the comment
public
getComment() : string|null
Return values
string|nullgetCommentUrl()
Get the comment URL of the cookie
public
getCommentUrl() : string|null
Return values
string|nullgetDiscard()
Get whether or not this is a session cookie
public
getDiscard() : null|bool
Return values
null|boolgetDomain()
Get the domain
public
getDomain() : string|null
Return values
string|nullgetExpires()
The UNIX timestamp when the cookie expires
public
getExpires() : mixed
getHttpOnly()
Get whether or not this is an HTTP only cookie
public
getHttpOnly() : bool
Return values
boolgetMaxAge()
Maximum lifetime of the cookie in seconds
public
getMaxAge() : int|null
Return values
int|nullgetName()
Get the cookie name
public
getName() : string
Return values
stringgetPath()
Get the path
public
getPath() : string
Return values
stringgetPorts()
Get an array of acceptable ports this cookie can be used with
public
getPorts() : array<string|int, mixed>
Return values
array<string|int, mixed>getSecure()
Get whether or not this is a secure cookie
public
getSecure() : null|bool
Return values
null|boolgetValue()
Get the cookie value
public
getValue() : string
Return values
stringgetVersion()
Version of the cookie specification. RFC 2965 is 1
public
getVersion() : mixed
isExpired()
Check if the cookie is expired
public
isExpired() : bool
Return values
boolmatchesDomain()
Check if the cookie matches a domain value
public
matchesDomain(string $domain) : bool
Parameters
- $domain : string
-
Domain to check against
Return values
boolmatchesPath()
Check if the cookie matches a path value
public
matchesPath(string $path) : bool
Parameters
- $path : string
-
Path to check against
Return values
boolmatchesPort()
Check if the cookie is compatible with a specific port
public
matchesPort(int $port) : bool
Parameters
- $port : int
-
Port to check
Return values
boolsetAttribute()
Set a cookie data attribute
public
setAttribute(string $name, string $value) : Cookie
Parameters
- $name : string
-
Name of the attribute to set
- $value : string
-
Value to set
Return values
CookiesetComment()
Set the comment of the cookie
public
setComment(string $comment) : Cookie
Parameters
- $comment : string
-
Cookie comment
Return values
CookiesetCommentUrl()
Set the comment URL of the cookie
public
setCommentUrl(string $commentUrl) : Cookie
Parameters
- $commentUrl : string
-
Cookie comment URL for more information
Return values
CookiesetDiscard()
Set whether or not this is a session cookie
public
setDiscard(bool $discard) : Cookie
Parameters
- $discard : bool
-
Set to true or false if this is a session cookie
Return values
CookiesetDomain()
Set the domain of the cookie
public
setDomain(string $domain) : Cookie
Parameters
- $domain : string
Return values
CookiesetExpires()
Set the unix timestamp for which the cookie will expire
public
setExpires(int $timestamp) : Cookie
Parameters
- $timestamp : int
-
Unix timestamp
Return values
CookiesetHttpOnly()
Set whether or not this is an HTTP only cookie
public
setHttpOnly(bool $httpOnly) : Cookie
Parameters
- $httpOnly : bool
-
Set to true or false if this is HTTP only
Return values
CookiesetMaxAge()
Set the max-age of the cookie
public
setMaxAge(int $maxAge) : Cookie
Parameters
- $maxAge : int
-
Max age of the cookie in seconds
Return values
CookiesetName()
Set the cookie name
public
setName(string $name) : Cookie
Parameters
- $name : string
-
Cookie name
Return values
CookiesetPath()
Set the path of the cookie
public
setPath(string $path) : Cookie
Parameters
- $path : string
-
Path of the cookie
Return values
CookiesetPorts()
Set a list of acceptable ports this cookie can be used with
public
setPorts(array<string|int, mixed> $ports) : Cookie
Parameters
- $ports : array<string|int, mixed>
-
Array of acceptable ports
Return values
CookiesetSecure()
Set whether or not the cookie is secure
public
setSecure(bool $secure) : Cookie
Parameters
- $secure : bool
-
Set to true or false if secure
Return values
CookiesetValue()
Set the cookie value
public
setValue(string $value) : Cookie
Parameters
- $value : string
-
Cookie value
Return values
CookiesetVersion()
Set the cookie version
public
setVersion(string|int $version) : Cookie
Parameters
- $version : string|int
-
Version to set
Return values
CookietoArray()
Get the cookie as an array
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
getInvalidCharacters()
Gets an array of invalid cookie characters
protected
static getInvalidCharacters() : array<string|int, mixed>
Return values
array<string|int, mixed>setData()
Set a value and return the cookie object
private
setData(string $key, string $value) : Cookie
Parameters
- $key : string
-
Key to set
- $value : string
-
Value to set