Skip to content

Latest commit

 

History

History
507 lines (189 loc) · 5.84 KB

SessionCookieJar.md

File metadata and controls

507 lines (189 loc) · 5.84 KB

SessionCookieJar

Persists cookies in the client session

Properties

sessionKey

private string $sessionKey

storeSessionCookies

private bool $storeSessionCookies

Methods

__construct

Create a new SessionCookieJar object

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

Parameters:

Parameter Type Description
$sessionKey string Session key name to store the cookie
data in session
$storeSessionCookies bool Set to true to store session cookies
in the cookie jar.

__destruct

Saves cookies to session when shutting down

public __destruct(): mixed

save

Save cookies to the client session

public save(): void

load

Load the contents of the client session into the data array

protected load(): void

Inherited methods

__construct

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

Parameters:

Parameter Type Description
$strictMode bool Set to true to throw exceptions when invalid
cookies are added to the cookie jar.
$cookieArray array Array of SetCookie objects or a hash of
arrays that can be used with the SetCookie
constructor

fromArray

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

public static fromArray(array $cookies, string $domain): self
  • This method is static.

Parameters:

Parameter Type Description
$cookies array Cookies to create the jar from
$domain string Domain to set the cookies to

shouldPersist

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

public static shouldPersist(\GuzzleHttp\Cookie\SetCookie $cookie, bool $allowSessionCookies = false): bool
  • This method is static.

Parameters:

Parameter Type Description
$cookie \GuzzleHttp\Cookie\SetCookie Being evaluated.
$allowSessionCookies bool If we should persist session cookies

getCookieByName

Finds and returns the cookie based on the name

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

Parameters:

Parameter Type Description
$name string cookie name to search for

Return Value:

cookie that was found or null if not found


toArray

Converts the cookie jar to an array.

public toArray(): array

clear

Remove cookies currently held in the cookie jar.

public clear(?string $domain = null, ?string $path = null, ?string $name = null): void

Parameters:

Parameter Type Description
$domain ?string Clears cookies matching a domain
$path ?string Clears cookies matching a domain and path
$name ?string Clears cookies matching a domain, path, and name

clearSessionCookies

Discard all sessions cookies.

public clearSessionCookies(): void

setCookie

Sets a cookie in the cookie jar.

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

Parameters:

Parameter Type Description
$cookie \GuzzleHttp\Cookie\SetCookie Cookie to set.

Return Value:

Returns true on success or false on failure


count

public count(): int

getIterator

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

extractCookies

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

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

Parameters:

Parameter Type Description
$request \Psr\Http\Message\RequestInterface Request that was sent
$response \Psr\Http\Message\ResponseInterface Response that was received

getCookiePathFromRequest

Computes cookie path following RFC 6265 section 5.1.4

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

Parameters:

Parameter Type Description
$request \Psr\Http\Message\RequestInterface

See Also:


withCookieHeader

Create a request with added cookie headers.

public withCookieHeader(\Psr\Http\Message\RequestInterface $request): \Psr\Http\Message\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:

Parameter Type Description
$request \Psr\Http\Message\RequestInterface Request object to modify.

Return Value:

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(\GuzzleHttp\Cookie\SetCookie $cookie): void

Parameters:

Parameter Type Description
$cookie \GuzzleHttp\Cookie\SetCookie