FileCookieJar
extends ArrayCookieJar
in package
Persists non-session cookies using a JSON formatted file
Table of Contents
Properties
- $cookies : array<string|int, mixed>
- $filename : string
- $strictMode : bool
Methods
- __construct() : mixed
- Create a new FileCookieJar object
- __destruct() : mixed
- Saves the file when shutting down
- add() : bool
- Add a cookie to the cookie cookieJar
- addCookiesFromResponse() : mixed
- Add cookies from a {@see Guzzle\Http\Message\Response} object
- all() : array<string|int, mixed>
- Get all of the matching cookies
- count() : int
- Returns the total number of stored cookies
- getIterator() : ArrayIterator
- Returns an iterator
- getMatchingCookies() : array<string|int, mixed>
- Get cookies matching a request object
- remove() : CookieJarInterface
- Remove cookies currently held in the Cookie cookieJar.
- removeExpired() : CookieJarInterface
- Delete any expired cookies
- removeTemporary() : CookieJarInterface
- Discard all temporary cookies.
- serialize() : string
- Serializes the cookie cookieJar
- setStrictMode() : self
- Enable or disable strict mode on the cookie jar
- unserialize() : mixed
- Unserializes the cookie cookieJar
- load() : mixed
- Load the contents of the json formatted file into the data array and discard any unsaved state
- persist() : mixed
- Save the contents of the data array to the file
- removeCookieIfEmpty() : mixed
- If a cookie already exists and the server asks to set it again with a null value, the cookie must be deleted.
Properties
$cookies
protected
array<string|int, mixed>
$cookies
= array()
Loaded cookie data
$filename
protected
string
$filename
filename
$strictMode
protected
bool
$strictMode
Whether or not strict mode is enabled. When enabled, exceptions will be thrown for invalid cookies
Methods
__construct()
Create a new FileCookieJar object
public
__construct(string $cookieFile) : mixed
Parameters
- $cookieFile : string
-
File to store the cookie data
Tags
__destruct()
Saves the file when shutting down
public
__destruct() : mixed
add()
Add a cookie to the cookie cookieJar
public
add(Cookie $cookie) : bool
Parameters
- $cookie : Cookie
-
Cookie to add
Return values
bool —Returns true on success or false on failure
addCookiesFromResponse()
Add cookies from a {@see Guzzle\Http\Message\Response} object
public
addCookiesFromResponse(Response $response[, RequestInterface $request = null ]) : mixed
Parameters
- $response : Response
-
Response object
- $request : RequestInterface = null
-
Request that received the response
all()
Get all of the matching cookies
public
all([mixed $domain = null ][, mixed $path = null ][, mixed $name = null ][, mixed $skipDiscardable = false ][, mixed $skipExpired = true ]) : array<string|int, mixed>
Parameters
- $domain : mixed = null
-
Domain of the cookie
- $path : mixed = null
-
Path of the cookie
- $name : mixed = null
-
Name of the cookie
- $skipDiscardable : mixed = false
-
Set to TRUE to skip cookies with the Discard attribute.
- $skipExpired : mixed = true
-
Set to FALSE to include expired
Return values
array<string|int, mixed> —Returns an array of Cookie objects
count()
Returns the total number of stored cookies
public
count() : int
Return values
intgetIterator()
Returns an iterator
public
getIterator() : ArrayIterator
Return values
ArrayIteratorgetMatchingCookies()
Get cookies matching a request object
public
getMatchingCookies(RequestInterface $request) : array<string|int, mixed>
Parameters
- $request : RequestInterface
-
Request object to match
Return values
array<string|int, mixed>remove()
Remove cookies currently held in the Cookie cookieJar.
public
remove([mixed $domain = null ][, mixed $path = null ][, mixed $name = null ]) : CookieJarInterface
Invoking this method without arguments will empty the whole Cookie cookieJar. If given a $domain argument only cookies belonging to that domain will be removed. If given a $domain and $path argument, cookies belonging to the specified path within that domain are removed. If given all three arguments, then the cookie with the specified name, path and domain is removed.
Parameters
- $domain : mixed = null
-
Set to clear only cookies matching a domain
- $path : mixed = null
-
Set to clear only cookies matching a domain and path
- $name : mixed = null
-
Set to clear only cookies matching a domain, path, and name
Return values
CookieJarInterfaceremoveExpired()
Delete any expired cookies
public
removeExpired() : CookieJarInterface
Return values
CookieJarInterfaceremoveTemporary()
Discard all temporary cookies.
public
removeTemporary() : CookieJarInterface
Scans for all cookies in the cookieJar with either no expire field or a true discard flag. To be called when the user agent shuts down according to RFC 2965.
Return values
CookieJarInterfaceserialize()
Serializes the cookie cookieJar
public
serialize() : string
Return values
stringsetStrictMode()
Enable or disable strict mode on the cookie jar
public
setStrictMode(bool $strictMode) : self
Parameters
- $strictMode : bool
-
Set to true to throw exceptions when invalid cookies are added. False to ignore them.
Return values
selfunserialize()
Unserializes the cookie cookieJar
public
unserialize(mixed $data) : mixed
Parameters
- $data : mixed
load()
Load the contents of the json formatted file into the data array and discard any unsaved state
protected
load() : mixed
persist()
Save the contents of the data array to the file
protected
persist() : mixed
Tags
removeCookieIfEmpty()
If a cookie already exists and the server asks to set it again with a null value, the cookie must be deleted.
private
removeCookieIfEmpty(Cookie $cookie) : mixed
Parameters
- $cookie : Cookie