Documentation

SessionCookieJar extends CookieJar
in package

Persists cookies in the client session

Table of Contents

$cookies  : array<string|int, SetCookie>
$sessionKey  : string
$storeSessionCookies  : bool
$strictMode  : bool
__construct()  : mixed
Create a new SessionCookieJar object
__destruct()  : mixed
Saves cookies to session when shutting down
clear()  : void
Remove cookies currently held in the cookie jar.
clearSessionCookies()  : void
Discard all sessions cookies.
count()  : int
extractCookies()  : void
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
getIterator()  : ArrayIterator<int, SetCookie>
save()  : void
Save cookies to the client session
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.
load()  : void
Load the contents of the client session into the data array
getCookiePathFromRequest()  : string
Computes cookie path following RFC 6265 section 5.1.4
removeCookieIfEmpty()  : void
If a cookie already exists and the server asks to set it again with a null value, the cookie must be deleted.

Properties

$storeSessionCookies

private bool $storeSessionCookies

Control whether to persist session cookies or not.

Methods

__construct()

Create a new SessionCookieJar object

public __construct(string $sessionKey[, bool $storeSessionCookies = false ]) : mixed
Parameters
$sessionKey : string

Session key name to store the cookie data in session

$storeSessionCookies : bool = false

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

Return values
mixed

__destruct()

Saves cookies to session when shutting down

public __destruct() : mixed
Return values
mixed

clear()

Remove cookies currently held in the cookie jar.

public clear([string|null $domain = null ][, string|null $path = null ][, string|null $name = null ]) : void
Parameters
$domain : string|null = null

Clears cookies matching a domain

$path : string|null = null

Clears cookies matching a domain and path

$name : string|null = null

Clears cookies matching a domain, path, and name

Tags
inheritDoc
Return values
void

clearSessionCookies()

Discard all sessions cookies.

public clearSessionCookies() : void
Tags
inheritDoc
Return values
void

count()

public count() : int
Return values
int

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

save()

Save cookies to the client session

public save() : void
Return values
void

setCookie()

Sets a cookie in the cookie jar.

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

Cookie to set.

Tags
inheritDoc
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>
Tags
inheritDoc
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.

load()

Load the contents of the client session into the data array

protected load() : void
Return values
void

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

Search results