Class
          CookieCollection
              
      
  Container class for cookies used in Http\Client.
Provides cookie jar like features for storing cookies between requests, as well as appending cookies to new requests.
Property Summary
- 
        $cookies protectedCake\Http\Cookie\CookieInterface[]Cookie objects 
Method Summary
- 
          __construct() publicConstructor 
- 
          add() publicAdd a cookie and get an updated collection. 
- 
          addFromResponse() publicCreate a new collection that includes cookies from the response. 
- 
          addToRequest() publicAdd cookies that match the path/domain/expiration to the request. 
- 
          checkCookies() protectedChecks if only valid cookie objects are in the array 
- 
          convertCookieToArray() protectedConvert the cookie into an array of its properties. 
- 
          count() publicGet the number of cookies in the collection. 
- 
          createFromHeader() public staticCreate a Cookie Collection from an array of Set-Cookie Headers 
- 
          createFromServerRequest() public staticCreate a new collection from the cookies in a ServerRequest 
- 
          findMatchingCookies() protectedFind cookies matching the scheme, host, and path 
- 
          get() publicGet stored cookies for a URL. 
- 
          getAll() publicGet all the stored cookies as arrays. 
- 
          getIterator() publicGets the iterator 
- 
          has() publicCheck if a cookie with the given name exists 
- 
          parseSetCookieHeader() protected staticParse Set-Cookie headers into array 
- 
          remove() publicCreate a new collection with all cookies matching $name removed. 
- 
          removeExpiredCookies() protectedRemove expired cookies from the collection. 
- 
          setRequestDefaults() protectedApply path and host to the set of cookies if they are not set. 
- 
          store() publicStore the cookies from a response. 
Method Detail
__construct() ¶ public
__construct(array $cookies = [])Constructor
Parameters
- 
                array$cookies optional
add() ¶ public
add(Cake\Http\Cookie\CookieInterface $cookie): staticAdd a cookie and get an updated collection.
Cookies are stored by id. This means that there can be duplicate cookies if a cookie collection is used for cookies across multiple domains. This can impact how get(), has() and remove() behave.
Parameters
- 
                Cake\Http\Cookie\CookieInterface$cookie
- Cookie instance to add. 
Returns
staticaddFromResponse() ¶ public
addFromResponse(Psr\Http\Message\ResponseInterface $response, Psr\Http\Message\RequestInterface $request): staticCreate a new collection that includes cookies from the response.
Parameters
- 
                Psr\Http\Message\ResponseInterface$response
- Response to extract cookies from. 
- 
                Psr\Http\Message\RequestInterface$request
- Request to get cookie context from. 
Returns
staticaddToRequest() ¶ public
addToRequest(Psr\Http\Message\RequestInterface $request, array $extraCookies = []): Psr\Http\Message\RequestInterfaceAdd cookies that match the path/domain/expiration to the request.
This allows CookieCollections to be used as a 'cookie jar' in an HTTP client situation. Cookies that match the request's domain + path that are not expired when this method is called will be applied to the request.
Parameters
- 
                Psr\Http\Message\RequestInterface$request
- The request to update. 
- 
                array$extraCookies optional
- Associative array of additional cookies to add into the request. This is useful when you have cookie data from outside the collection you want to send. 
Returns
Psr\Http\Message\RequestInterfaceAn updated request.
checkCookies() ¶ protected
checkCookies(array $cookies): voidChecks if only valid cookie objects are in the array
Parameters
- 
                array$cookies
- Array of cookie objects 
Returns
voidThrows
InvalidArgumentExceptionconvertCookieToArray() ¶ protected
convertCookieToArray(Cake\Http\Cookie\CookieInterface $cookie): arrayConvert the cookie into an array of its properties.
Primarily useful where backwards compatibility is needed.
Parameters
- 
                Cake\Http\Cookie\CookieInterface$cookie
- Cookie object. 
Returns
arraycreateFromHeader() ¶ public static
createFromHeader(array $header): staticCreate a Cookie Collection from an array of Set-Cookie Headers
Parameters
- 
                array$header
- The array of set-cookie header values. 
Returns
staticcreateFromServerRequest() ¶ public static
createFromServerRequest(Psr\Http\Message\ServerRequestInterface $request): staticCreate a new collection from the cookies in a ServerRequest
Parameters
- 
                Psr\Http\Message\ServerRequestInterface$request
- The request to extract cookie data from 
Returns
staticfindMatchingCookies() ¶ protected
findMatchingCookies(string $scheme, string $host, string $path): arrayFind cookies matching the scheme, host, and path
Parameters
- 
                string$scheme
- The http scheme to match 
- 
                string$host
- The host to match. 
- 
                string$path
- The path to match 
Returns
arrayAn array of cookie name/value pairs
get() ¶ public
get(string $url): arrayGet stored cookies for a URL.
Finds matching stored cookies and returns a simple array of name => value
Parameters
- 
                string$url
- The URL to find cookies for. 
Returns
arrayhas() ¶ public
has(string $name): boolCheck if a cookie with the given name exists
Parameters
- 
                string$name
- The cookie name to check. 
Returns
boolTrue if the cookie exists, otherwise false.
parseSetCookieHeader() ¶ protected static
parseSetCookieHeader(array $values): Cake\Http\Cookie\Cookie[]Parse Set-Cookie headers into array
Parameters
- 
                array$values
- List of Set-Cookie Header values. 
Returns
Cake\Http\Cookie\Cookie[]An array of cookie objects
remove() ¶ public
remove(string $name): staticCreate a new collection with all cookies matching $name removed.
If the cookie is not in the collection, this method will do nothing.
Parameters
- 
                string$name
- The name of the cookie to remove. 
Returns
staticremoveExpiredCookies() ¶ protected
removeExpiredCookies(string $host, string $path): voidRemove expired cookies from the collection.
Parameters
- 
                string$host
- The host to check for expired cookies on. 
- 
                string$path
- The path to check for expired cookies on. 
Returns
voidsetRequestDefaults() ¶ protected
setRequestDefaults(array $cookies, string $host, string $path): arrayApply path and host to the set of cookies if they are not set.
Parameters
- 
                array$cookies
- An array of cookies to update. 
- 
                string$host
- The host to set. 
- 
                string$path
- The path to set. 
Returns
arrayAn array of updated cookies.
store() ¶ public
store(Response $response, string $url): voidStore the cookies from a response.
Store the cookies that haven't expired. If a cookie has been expired and is currently stored, it will be removed.
Parameters
- 
                Response$response
- The response to read cookies from 
- 
                string$url
- The request URL used for default host/path values. 
Returns
void