\GuzzleHttp\CookieFileCookieJar

Persists non-session cookies using a JSON formatted file

Summary

Methods
Properties
Constants
__construct()
fromArray()
getCookieValue()
shouldPersist()
getCookieByName()
toArray()
clear()
clearSessionCookies()
setCookie()
count()
getIterator()
extractCookies()
withCookieHeader()
__destruct()
save()
load()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
getCookiePathFromRequest()
removeCookieIfEmpty()
$cookies
$strictMode
$filename
$storeSessionCookies
N/A

Properties

$strictMode

$strictMode : boolean

Type

boolean

$filename

$filename : string

Type

string — filename

$storeSessionCookies

$storeSessionCookies : boolean

Type

boolean — Control whether to persist session cookies or not.

Methods

__construct()

__construct(string  $cookieFile, boolean  $storeSessionCookies = false) 

Create a new FileCookieJar object

Parameters

string $cookieFile

File to store the cookie data

boolean $storeSessionCookies

Set to true to store session cookies in the cookie jar.

Throws

\RuntimeException

if the file cannot be found or created

fromArray()

fromArray(array  $cookies, string  $domain) : self

Create a new Cookie jar from an associative array and domain.

Parameters

array $cookies

Cookies to create the jar from

string $domain

Domain to set the cookies to

Returns

self

getCookieValue()

getCookieValue(  $value) 

Parameters

$value

shouldPersist()

shouldPersist(\GuzzleHttp\Cookie\SetCookie  $cookie, boolean  $allowSessionCookies = false) : boolean

Evaluate if this cookie should be persisted to storage that survives between requests.

Parameters

\GuzzleHttp\Cookie\SetCookie $cookie

Being evaluated.

boolean $allowSessionCookies

If we should persist session cookies

Returns

boolean

getCookieByName()

getCookieByName(string  $name) : \GuzzleHttp\Cookie\SetCookie|null

Finds and returns the cookie based on the name

Parameters

string $name

cookie name to search for

Returns

\GuzzleHttp\Cookie\SetCookie|null —

cookie that was found or null if not found

toArray()

toArray() : array

Converts the cookie jar to an array.

Returns

array

clear()

clear(string  $domain = null, string  $path = null, string  $name = null) : \GuzzleHttp\Cookie\CookieJarInterface

Remove cookies currently held in the cookie jar.

Invoking this method without arguments will empty the whole cookie jar. 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

string $domain

Clears cookies matching a domain

string $path

Clears cookies matching a domain and path

string $name

Clears cookies matching a domain, path, and name

Returns

\GuzzleHttp\Cookie\CookieJarInterface

clearSessionCookies()

clearSessionCookies() 

Discard all sessions cookies.

Removes cookies that don't have an expire field or a have a discard field set to true. To be called when the user agent shuts down according to RFC 2965.

setCookie()

setCookie(\GuzzleHttp\Cookie\SetCookie  $cookie) : boolean

Sets a cookie in the cookie jar.

Parameters

\GuzzleHttp\Cookie\SetCookie $cookie

Cookie to set.

Returns

boolean —

Returns true on success or false on failure

count()

count() 

getIterator()

getIterator() 

extractCookies()

extractCookies(\Psr\Http\Message\RequestInterface  $request, \Psr\Http\Message\ResponseInterface  $response) 

Extract cookies from an HTTP response and store them in the CookieJar.

Parameters

\Psr\Http\Message\RequestInterface $request

Request that was sent

\Psr\Http\Message\ResponseInterface $response

Response that was received

withCookieHeader()

withCookieHeader(\Psr\Http\Message\RequestInterface  $request) : \Psr\Http\Message\RequestInterface

Create a request with added cookie headers.

If no matching cookies are found in the cookie jar, then no Cookie header is added to the request and the same request is returned.

Parameters

\Psr\Http\Message\RequestInterface $request

Request object to modify.

Returns

\Psr\Http\Message\RequestInterface

returns the modified request.

__destruct()

__destruct() 

Saves the file when shutting down

save()

save(string  $filename) 

Saves the cookies to a file.

Parameters

string $filename

File to save

Throws

\RuntimeException

if the file cannot be found or created

load()

load(string  $filename) 

Load cookies from a JSON formatted file.

Old cookies are kept unless overwritten by newly loaded ones.

Parameters

string $filename

Cookie file to load.

Throws

\RuntimeException

if the file cannot be loaded.

getCookiePathFromRequest()

getCookiePathFromRequest(\Psr\Http\Message\RequestInterface  $request) : string

Computes cookie path following RFC 6265 section 5.1.4

Parameters

\Psr\Http\Message\RequestInterface $request

Returns

string

removeCookieIfEmpty()

removeCookieIfEmpty(\GuzzleHttp\Cookie\SetCookie  $cookie) 

If a cookie already exists and the server asks to set it again with a null value, the cookie must be deleted.

Parameters

\GuzzleHttp\Cookie\SetCookie $cookie