Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
GuzzleHttp\Cookie\CookieJar Class Reference
Inheritance diagram for GuzzleHttp\Cookie\CookieJar:
GuzzleHttp\Cookie\CookieJarInterface GuzzleHttp\Cookie\FileCookieJar GuzzleHttp\Cookie\SessionCookieJar

Public Member Functions

 __construct (bool $strictMode=false, array $cookieArray=[])
 
 clear (string $domain=null, string $path=null, string $name=null)
 Remove cookies currently held in the cookie jar.
 
 clearSessionCookies ()
 Discard all sessions cookies.
 
 count ()
 
 extractCookies (RequestInterface $request, ResponseInterface $response)
 Extract cookies from an HTTP response and store them in the CookieJar.
 
 getCookieByName (string $name)
 Finds and returns the cookie based on the name.
 
 getIterator ()
 
 setCookie (SetCookie $cookie)
 Sets a cookie in the cookie jar.
 
 toArray ()
 Converts the cookie jar to an array.
 
 withCookieHeader (RequestInterface $request)
 Create a request with added cookie headers.
 

Static Public Member Functions

static fromArray (array $cookies, string $domain)
 Create a new Cookie jar from an associative array and domain.
 
static shouldPersist (SetCookie $cookie, bool $allowSessionCookies=false)
 Evaluate if this cookie should be persisted to storage that survives between requests.
 

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\Cookie\CookieJar::__construct ( bool $strictMode = false,
array $cookieArray = [] )
Parameters
bool$strictModeSet to true to throw exceptions when invalid cookies are added to the cookie jar.
array$cookieArrayArray of SetCookie objects or a hash of arrays that can be used with the SetCookie constructor

Member Function Documentation

◆ clear()

GuzzleHttp\Cookie\CookieJar::clear ( string $domain = null,
string $path = null,
string $name = null )

Remove cookies currently held in the cookie jar.

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
string | null$domainClears cookies matching a domain
string | null$pathClears cookies matching a domain and path
string | null$nameClears cookies matching a domain, path, and name

Implements GuzzleHttp\Cookie\CookieJarInterface.

◆ clearSessionCookies()

GuzzleHttp\Cookie\CookieJar::clearSessionCookies ( )

Discard all sessions cookies.

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.

Implements GuzzleHttp\Cookie\CookieJarInterface.

◆ extractCookies()

GuzzleHttp\Cookie\CookieJar::extractCookies ( RequestInterface $request,
ResponseInterface $response )

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

Parameters
RequestInterface$requestRequest that was sent
ResponseInterface$responseResponse that was received

Implements GuzzleHttp\Cookie\CookieJarInterface.

◆ fromArray()

static GuzzleHttp\Cookie\CookieJar::fromArray ( array $cookies,
string $domain )
static

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

Parameters
array$cookiesCookies to create the jar from
string$domainDomain to set the cookies to

◆ getCookieByName()

GuzzleHttp\Cookie\CookieJar::getCookieByName ( string $name)

Finds and returns the cookie based on the name.

Parameters
string$namecookie name to search for
Return values
SetCookie|nullcookie that was found or null if not found

◆ getIterator()

GuzzleHttp\Cookie\CookieJar::getIterator ( )
Return values
ArrayIterator<int,SetCookie>

◆ setCookie()

GuzzleHttp\Cookie\CookieJar::setCookie ( SetCookie $cookie)

Sets a cookie in the cookie jar.

Parameters
SetCookie$cookieCookie to set.
Return values
boolReturns true on success or false on failure

Implements GuzzleHttp\Cookie\CookieJarInterface.

◆ shouldPersist()

static GuzzleHttp\Cookie\CookieJar::shouldPersist ( SetCookie $cookie,
bool $allowSessionCookies = false )
static

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

Parameters
SetCookie$cookieBeing evaluated.
bool$allowSessionCookiesIf we should persist session cookies

◆ toArray()

GuzzleHttp\Cookie\CookieJar::toArray ( )

Converts the cookie jar to an array.

Implements GuzzleHttp\Cookie\CookieJarInterface.

◆ withCookieHeader()

GuzzleHttp\Cookie\CookieJar::withCookieHeader ( RequestInterface $request)

Create a request with added cookie headers.

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
RequestInterface$requestRequest object to modify.
Return values
RequestInterfacereturns the modified request.

Implements GuzzleHttp\Cookie\CookieJarInterface.


The documentation for this class was generated from the following file: