Persists cookies in the client session
- Full name:
\GuzzleHttp\Cookie\SessionCookieJar
- Parent class:
\GuzzleHttp\Cookie\CookieJar
private string $sessionKey
private bool $storeSessionCookies
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. |
Saves cookies to session when shutting down
public __destruct(): mixed
Save cookies to the client session
public save(): void
Load the contents of the client session into the data array
protected load(): void
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 |
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 |
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 |
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
Converts the cookie jar to an array.
public toArray(): array
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 |
Discard all sessions cookies.
public clearSessionCookies(): void
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
public count(): int
public getIterator(): \ArrayIterator<int,\GuzzleHttp\Cookie\SetCookie>
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 |
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:
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.
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 |