CookieJarInterface
extends
Countable, IteratorAggregate
in
Stores HTTP cookies.
It extracts cookies from HTTP requests, and returns them in HTTP responses. CookieJarInterface instances automatically expire contained cookies when necessary. Subclasses are also responsible for storing and retrieving cookies from a file, database, etc.
Tags
Table of Contents
- clear() : CookieJarInterface
- Remove cookies currently held in the cookie jar.
- clearSessionCookies() : mixed
- Discard all sessions cookies.
- extractCookies() : mixed
- Extract cookies from an HTTP response and store them in the CookieJar.
- setCookie() : bool
- Sets a cookie in the cookie jar.
- toArray() : array<string|int, mixed>
- Converts the cookie jar to an array.
- withCookieHeader() : RequestInterface
- Create a request with added cookie headers.
Methods
clear()
Remove cookies currently held in the cookie jar.
public
clear([string|null $domain = null ][, string|null $path = null ][, string|null $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 : 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
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 —extractCookies()
Extract cookies from an HTTP response and store them in the CookieJar.
public
extractCookies(RequestInterface $request, ResponseInterface $response) : mixed
Parameters
- $request : RequestInterface
-
Request that was sent
- $response : ResponseInterface
-
Response that was received
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
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.