Cookie Collection
Provides an immutable collection of cookies objects. Adding or removing to a collection returns a new collection that you must retain.
$cookies
protected __construct( array $cookies [] )
Constructor
$cookies
optional [] add( Cake\Http\Cookie\CookieInterface $cookie )
Add 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.
Cake\Http\Cookie\CookieInterface
$cookie
Cake\Http\Cookie\CookieCollection
addFromResponse( Psr\Http\Message\ResponseInterface $response , Psr\Http\Message\RequestInterface $request )
Create a new collection that includes cookies from the response.
$response
$request
Cake\Http\Cookie\CookieCollection
addToRequest( Psr\Http\Message\RequestInterface $request , array $extraCookies [] )
Add 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.
$request
$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.
checkCookies( array $cookies )
Checks if only valid cookie objects are in the array
$cookies
count( )
Get the number of cookies in the collection.
Countable::count()
createFromHeader( array $header )
Create a Cookie Collection from an array of Set-Cookie Headers
$header
Cake\Http\Cookie\CookieCollection
createFromServerRequest( Psr\Http\Message\ServerRequestInterface $request )
Create a new collection from the cookies in a ServerRequest
$request
Cake\Http\Cookie\CookieCollection
findMatchingCookies( string $scheme , string $host , string $path )
Find cookies matching the scheme, host, and path
$scheme
$host
$path
get( string $name )
Get the first cookie by name.
$name
Cake\Http\Cookie\CookieInterface
|nullgetIterator( )
Gets the iterator
IteratorAggregate::getIterator()
has( string $name )
Check if a cookie with the given name exists
$name
parseSetCookieHeader( array $values )
Parse Set-Cookie headers into array
$values
Cake\Http\Cookie\Cookie[]
remove( string $name )
Create a new collection with all cookies matching $name removed.
If the cookie is not in the collection, this method will do nothing.
$name
Cake\Http\Cookie\CookieCollection
removeExpiredCookies( string $host , string $path )
Remove expired cookies from the collection.
$host
$path
setRequestDefaults( array $cookies , string $host , string $path )
Apply path and host to the set of cookies if they are not set.
$cookies
$host
$path
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.5/class-Cake.Http.Cookie.CookieCollection.html