Zend\Http\Cookies
A Zend\Http\Cookies object is designed to contain and maintain HTTP cookies, and should be used along with Zend\Http\Client in order to manage cookies across HTTP requests and responses.
The class contains an array of Zend\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 Zend\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 Zend\Http\Client\Cookies::COOKIE_STRING_ARRAY) or one unified string for all cookies
(by passing Zend\Http\Client\Cookies::COOKIE_STRING_CONCAT).
Synopsis
class Cookies
extends Headers
{
- // constants
- const COOKIE_OBJECT = 0;
- const COOKIE_STRING_ARRAY = 1;
- const COOKIE_STRING_CONCAT = 2;
- const COOKIE_STRING_CONCAT_STRICT = 3;
- // members
- protected Cookies $cookies;
- protected Headers $headers;
- protected array $rawCookies;
- // Inherited members from Headers
- protected PluginClassLoader $pluginClassLoader;
- protected array $headersKeys;
- protected array $headers;
- // methods
- public static void fromString()
- public void addCookie()
- public void addCookiesFromResponse()
- public array|string getAllCookies()
- public array|string getMatchingCookies()
- public SetCookie|string getCookie()
- protected array|string _flattenCookiesArray()
- protected array _matchDomain()
- protected array _matchPath()
- public static Cookies fromResponse()
- public bool isEmpty()
- public Cookies reset()
- // Inherited methods from Headers
- public static Headers fromString()
- public Headers setPluginClassLoader()
- public PluginClassLocator getPluginClassLoader()
- public Headers addHeaders()
- public Headers addHeaderLine()
- public Headers addHeader()
- public bool removeHeader()
- public Headers clearHeaders()
- public HeaderInterface|ArrayIterator get()
- public bool has()
- public void next()
- public mixed key()
- public bool valid()
- public void rewind()
- public HeaderInterface current()
- public int count()
- public string toString()
- public array toArray()
- public bool forceLoading()
- protected mixed|void lazyLoadHeader()
- protected static string createKey()
Hierarchy
Extends
Tasks
Line | Task |
---|---|
343+ | Add the $uri functionality. |
383+ | determine how to produce single line headers, if they are supported |
Constants
Name | Value |
---|---|
COOKIE_OBJECT | 0 |
COOKIE_STRING_ARRAY | 1 |
COOKIE_STRING_CONCAT | 2 |
COOKIE_STRING_CONCAT_STRICT | 3 |
Members
protected
- $headers — \Zend\Http\Headers
- $headers — array
- $headersKeys — array
- $pluginClassLoader — Zend\Http\PluginClassLoader
- $rawCookies — array
Methods
protected
- _flattenCookiesArray() — Helper function to recursively flatten an array. Should be used when exporting the cookies array (or parts of it)
- _matchDomain() — Return a subset of the cookies array matching a specific domain
- _matchPath() — Return a subset of a domain-matching cookies that also match a specified path
public
- addCookie() — Add a cookie to the class. Cookie should be passed either as a Zend\Http\Header\Cookie object or as a string - in which case an object is created from the string.
- addCookiesFromResponse() — Parse an HTTP response, adding all the cookies set in that response
- 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.
- fromString()
- getAllCookies() — Get all cookies in the cookie jar as an array
- getCookie() — Get a specific cookie according to a URI and name
- 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.
- isEmpty() — Tells if the array of cookies is empty
- reset() — Empties the cookieJar of any cookie
Inherited from Zend\Http\Headers
protected
- createKey() — Create array key from header name
- lazyLoadHeader()
public
- addHeader() — Add a Header to this container, for raw values @see addHeaderLine() and addHeaders()
- addHeaderLine() — Add a raw header line, either in name => value, or as a single string 'name: value'
- addHeaders() — Add many headers at once
- clearHeaders() — Clear all 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
- current() — Return the current value for this iterator, lazy loading it if need be
- forceLoading() — By calling this, it will force parsing and loading of all headers, after this count() will be accurate
- fromString() — Populates headers from string representation
- get() — Get all headers of a certain name/type
- getPluginClassLoader() — Return an instance of a PluginClassLocator, lazyload and inject map if necessary
- has() — Test for existence of a type of header
- key() — Return the current key for this object as an iterator
- next() — Advance the pointer for this object as an iterator
- removeHeader() — Remove a Header from the container
- rewind() — Reset the internal pointer for this object as an iterator
- setPluginClassLoader() — Set an alternate implementation for the PluginClassLoader
- toArray() — Return the headers container as an array
- toString() — Render all headers at once
- valid() — Is this iterator still valid?