Fully Qualified Name: | Laminas\Http\Cookies |
Extends: | Headers |
A Laminas\Http\Cookies object is designed to contain and maintain HTTP cookies, and should be used along with Laminas\Http\Client in order to manage cookies across HTTP requests and responses.
The class contains an array of Laminas\Http\Header\Cookie objects. Cookies can be added automatically from a request or manually. Then, the Cookies class can find and return the cookies needed for a specific HTTP request.
A special parameter can be passed to all methods of this class that return cookies: Cookies can be returned either in their native form (as Laminas\Http\Header\Cookie objects) or as strings - the later is suitable for sending as the value of the "Cookie" header in an HTTP request. You can also choose, when returning more than one cookie, whether to get an array of strings (by passing Laminas\Http\Client\Cookies::COOKIE_STRING_ARRAY) or one unified string for all cookies (by passing Laminas\Http\Client\Cookies::COOKIE_STRING_CONCAT).
Name | Description | Defined By |
---|---|---|
addCookie() | Add a cookie to the class. Cookie should be passed either as a Laminas\Http\Header\SetCookie object or as a string - in which case an object is created from the string. | Cookies |
addCookiesFromResponse() | Parse an HTTP response, adding all the cookies set in that response | Cookies |
addHeader() | Add a Header to this container, for raw values @see addHeaderLine() and addHeaders() | Headers |
addHeaderLine() | Add a raw header line, either in name => value, or as a single string 'name: value' | Headers |
addHeaders() | Add many headers at once | Headers |
clearHeaders() | Clear all headers | Headers |
count() | Return the number of headers in this contain, if all headers have not been parsed, actual count could increase if MultipleHeader objects exist in the Request/Response. If you need an exact count, iterate | Headers |
current() | Return the current value for this iterator, lazy loading it if need be | Headers |
forceLoading() | By calling this, it will force parsing and loading of all headers, after this count() will be accurate | Headers |
fromResponse() | Create a new Cookies object and automatically load into it all the cookies set in a Response object. If $uri is set, it will be considered as the requested URI for setting default domain and path of the cookie. | Cookies |
fromString() | Cookies | |
get() | Get all headers of a certain name/type | Headers |
getAllCookies() | Get all cookies in the cookie jar as an array | Cookies |
getCookie() | Get a specific cookie according to a URI and name | Cookies |
getMatchingCookies() | Return an array of all cookies matching a specific request according to the request URI, whether session cookies should be sent or not, and the time to consider as "now" when checking cookie expiry time. | Cookies |
getPluginClassLoader() | Return an instance of a PluginClassLocator, lazyload and inject map if necessary | Headers |
has() | Test for existence of a type of header | Headers |
isEmpty() | Tells if the array of cookies is empty | Cookies |
key() | Return the current key for this object as an iterator | Headers |
next() | Advance the pointer for this object as an iterator | Headers |
removeHeader() | Remove a Header from the container | Headers |
reset() | Empties the cookieJar of any cookie | Cookies |
rewind() | Reset the internal pointer for this object as an iterator | Headers |
setPluginClassLoader() | Set an alternate implementation for the PluginClassLoader | Headers |
toArray() | Return the headers container as an array | Headers |
toString() | Render all headers at once | Headers |
valid() | Is this iterator still valid? | Headers |
Add a cookie to the class. Cookie should be passed either as a Laminas\Http\Header\SetCookie object or as a string - in which case an object is created from the string.
Parameter Name | Type | Description |
---|---|---|
$cookie | \SetCookie|string | |
$refUri | \Uri\Uri|string | Optional |
Returns:
Parse an HTTP response, adding all the cookies set in that response
Parameter Name | Type | Description |
---|---|---|
$response | \Response | |
$refUri | \Uri\Uri|string | Requested |
Returns:
Add a Header to this container, for raw values @see addHeaderLine() and addHeaders()
Parameter Name | Type | Description |
---|---|---|
$header | \Header\HeaderInterface |
Returns: $this
Add a raw header line, either in name => value, or as a single string 'name: value'
This method allows for lazy-loading in that the parsing and instantiation of Header object will be delayed until they are retrieved by either get() or current()
Parameter Name | Type | Description |
---|---|---|
$headerFieldNameOrLine | string | |
$fieldValue | string | optional |
Returns: $this
Add many headers at once
Expects an array (or Traversable object) of type/value pairs.
Parameter Name | Type | Description |
---|---|---|
$headers | array|\Traversable |
Returns: $this
Clear all headers
Removes all headers from queue
Returns: $this
Return the number of headers in this contain, if all headers have not been parsed, actual count could increase if MultipleHeader objects exist in the Request/Response. If you need an exact count, iterate
Returns: int count of currently known headers
Return the current value for this iterator, lazy loading it if need be
Returns: array|\Header\HeaderInterface
By calling this, it will force parsing and loading of all headers, after this count() will be accurate
Returns: bool
Create a new Cookies object and automatically load into it all the cookies set in a Response object. If $uri is set, it will be considered as the requested URI for setting default domain and path of the cookie.
Parameter Name | Type | Description |
---|---|---|
$response | \Response | HTTP |
$refUri | \Uri\Uri|string | The |
Returns: static
Parameter Name | Type | Description |
---|---|---|
$string | ||
$string |
Returns: void
Get all headers of a certain name/type
Parameter Name | Type | Description |
---|---|---|
$name | string |
Returns: bool|\Header\HeaderInterface|\ArrayIterator
Get all cookies in the cookie jar as an array
Parameter Name | Type | Description |
---|---|---|
$retAs | int | Whether |
Returns: array|string
Get a specific cookie according to a URI and name
Parameter Name | Type | Description |
---|---|---|
$uri | \Uri\Uri|string | The |
$cookieName | string | The |
$retAs | int | Whether |
Returns: \SetCookie|string
Return an array of all cookies matching a specific request according to the request URI, whether session cookies should be sent or not, and the time to consider as "now" when checking cookie expiry time.
Parameter Name | Type | Description |
---|---|---|
$uri | string|\Uri\Uri | URI |
$matchSessionCookies | bool | Whether |
$retAs | int | Whether |
$now | int | Override |
Returns: array|string
Return an instance of a PluginClassLocator, lazyload and inject map if necessary
Returns: \PluginClassLocator
Test for existence of a type of header
Parameter Name | Type | Description |
---|---|---|
$name | string |
Returns: bool
Tells if the array of cookies is empty
Returns: bool
Return the current key for this object as an iterator
Returns: mixed
Advance the pointer for this object as an iterator
Returns: void
Remove a Header from the container
Parameter Name | Type | Description |
---|---|---|
$header | \Header\HeaderInterface |
Returns: bool
Empties the cookieJar of any cookie
Returns: $this
Reset the internal pointer for this object as an iterator
Returns: void
Set an alternate implementation for the PluginClassLoader
Parameter Name | Type | Description |
---|---|---|
$pluginClassLoader | \PluginClassLocator |
Returns: $this
Return the headers container as an array
Returns: array
Render all headers at once
This method handles the normal iteration of headers; it is up to the concrete classes to prepend with the appropriate status/request line.
Returns: string
Is this iterator still valid?
Returns: bool