Documentation

CookieJar
in package
implements CookieJarInterface

Cookie jar that stores cookies as an array

Interfaces, Classes and Traits

CookieJarInterface
Stores HTTP cookies.

Table of Contents

$cookies  : array<string|int, SetCookie>
$strictMode  : bool
__construct()  : mixed
clear()  : CookieJarInterface
Remove cookies currently held in the cookie jar.
clearSessionCookies()  : mixed
Discard all sessions cookies.
count()  : mixed
extractCookies()  : mixed
Extract cookies from an HTTP response and store them in the CookieJar.
fromArray()  : self
Create a new Cookie jar from an associative array and domain.
getCookieByName()  : SetCookie|null
Finds and returns the cookie based on the name
getCookieValue()  : mixed
getIterator()  : mixed
setCookie()  : bool
Sets a cookie in the cookie jar.
shouldPersist()  : bool
Evaluate if this cookie should be persisted to storage that survives between requests.
toArray()  : array<string|int, mixed>
Converts the cookie jar to an array.
withCookieHeader()  : RequestInterface
Create a request with added cookie headers.
getCookiePathFromRequest()  : string
Computes cookie path following RFC 6265 section 5.1.4
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

Methods

__construct()

public __construct([bool $strictMode = false ][, array<string|int, mixed> $cookieArray = [] ]) : mixed
Parameters
$strictMode : bool = false

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

$cookieArray : array<string|int, mixed> = []

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

Return values
mixed

clear()

Remove cookies currently held in the cookie jar.

public clear([mixed $domain = null ][, mixed $path = null ][, mixed $name = null ]) : CookieJarInterface

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
$domain : mixed = null

Clears cookies matching a domain

$path : mixed = null

Clears cookies matching a domain and path

$name : mixed = null

Clears cookies matching a domain, path, and name

Return values
CookieJarInterface

clearSessionCookies()

Discard all sessions cookies.

public clearSessionCookies() : mixed

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.

Return values
mixed

count()

public count() : mixed
Return values
mixed

fromArray()

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

public static fromArray(array<string|int, mixed> $cookies, string $domain) : self
Parameters
$cookies : array<string|int, mixed>

Cookies to create the jar from

$domain : string

Domain to set the cookies to

Return values
self

getCookieByName()

Finds and returns the cookie based on the name

public getCookieByName(string $name) : SetCookie|null
Parameters
$name : string

cookie name to search for

Return values
SetCookie|null

cookie that was found or null if not found

getCookieValue()

public static getCookieValue(mixed $value) : mixed
Parameters
$value : mixed
Tags
deprecated
Return values
mixed

getIterator()

public getIterator() : mixed
Return values
mixed

setCookie()

Sets a cookie in the cookie jar.

public setCookie(SetCookie $cookie) : bool
Parameters
$cookie : SetCookie

Cookie to set.

Return values
bool

Returns true on success or false on failure

shouldPersist()

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

public static shouldPersist(SetCookie $cookie[, bool $allowSessionCookies = false ]) : bool
Parameters
$cookie : SetCookie

Being evaluated.

$allowSessionCookies : bool = false

If we should persist session cookies

Return values
bool

toArray()

Converts the cookie jar to an array.

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

withCookieHeader()

Create a request with added cookie headers.

public withCookieHeader(RequestInterface $request) : RequestInterface

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
$request : RequestInterface

Request object to modify.

Return values
RequestInterface

returns the modified request.

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(SetCookie $cookie) : mixed
Parameters
$cookie : SetCookie
Return values
mixed

Search results