\GuzzleHttp\CookieCookieJar

Cookie jar that stores cookies as an array

Summary

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

Properties

$cookies

$cookies : \GuzzleHttp\Cookie\SetCookie[]

Type

SetCookie[] — Loaded cookie data

$strictMode

$strictMode : bool

Type

bool

Methods

__construct()

__construct(bool  $strictMode = false, array  $cookieArray = []) : mixed

Parameters

bool $strictMode

Set to true to throw exceptions when invalid cookies are added to the cookie jar.

array $cookieArray

Array of SetCookie objects or a hash of arrays that can be used with the SetCookie constructor

Returns

mixed —

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 —

shouldPersist()

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

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

Parameters

\GuzzleHttp\Cookie\SetCookie $cookie

Being evaluated.

bool $allowSessionCookies

If we should persist session cookies

Returns

bool —

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) : void

Remove cookies currently held in the cookie jar.

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

clearSessionCookies()

clearSessionCookies() : void

Discard all sessions cookies.

setCookie()

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

Sets a cookie in the cookie jar.

Parameters

\GuzzleHttp\Cookie\SetCookie $cookie

Cookie to set.

Returns

bool —

Returns true on success or false on failure

count()

count() : int

Returns

int —

getIterator()

getIterator() : \ArrayIterator<int,\GuzzleHttp\Cookie\SetCookie>

Returns

\ArrayIterator

extractCookies()

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

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.

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) : void

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