Zend Framework
3.0
|
A Zend object is designed to contain and maintain HTTP cookies, and should be used along with Zend in order to manage cookies across HTTP requests and responses. More...
Public Member Functions | |
addCookie ($cookie, $refUri=null) | |
Add a cookie to the class. | |
addCookiesFromResponse (Response $response, $refUri) | |
Parse an HTTP response, adding all the cookies set in that response. | |
getAllCookies ($retAs=self::COOKIE_OBJECT) | |
Get all cookies in the cookie jar as an array. | |
getMatchingCookies ($uri, $matchSessionCookies=true, $retAs=self::COOKIE_OBJECT, $now=null) | |
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. | |
getCookie ($uri, $cookieName, $retAs=self::COOKIE_OBJECT) | |
Get a specific cookie according to a URI and name. | |
isEmpty () | |
Tells if the array of cookies is empty. | |
reset () | |
Empties the cookieJar of any cookie. | |
Public Member Functions inherited from Headers | |
setPluginClassLoader (PluginClassLocator $pluginClassLoader) | |
Set an alternate implementation for the PluginClassLoader. | |
getPluginClassLoader () | |
Return an instance of a PluginClassLocator, lazyload and inject map if necessary. | |
addHeaders ($headers) | |
Add many headers at once. | |
addHeaderLine ($headerFieldNameOrLine, $fieldValue=null) | |
Add a raw header line, either in name => value, or as a single string 'name: value'. | |
addHeader (Header\HeaderInterface $header) | |
Add a Header to this container, for raw values. | |
removeHeader (Header\HeaderInterface $header) | |
Remove a Header from the container. | |
clearHeaders () | |
Clear all headers. | |
get ($name) | |
Get all headers of a certain name/type. | |
has ($name) | |
Test for existence of a type of header. | |
next () | |
Advance the pointer for this object as an iterator. | |
key () | |
Return the current key for this object as an iterator. | |
valid () | |
Is this iterator still valid? | |
rewind () | |
Reset the internal pointer for this object as an iterator. | |
current () | |
Return the current value for this iterator, lazy loading it if need be. | |
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. | |
toString () | |
Render all headers at once. | |
toArray () | |
Return the headers container as an array. | |
forceLoading () | |
By calling this, it will force parsing and loading of all headers, after this count() will be accurate. | |
Static Public Member Functions | |
static | fromString ($string) |
static | fromResponse (Response $response, $refUri) |
Create a new Cookies object and automatically load into it all the cookies set in a Response object. | |
Static Public Member Functions inherited from Headers | |
static | fromString ($string) |
Populates headers from string representation. | |
Public Attributes | |
const | COOKIE_OBJECT = 0 |
Return cookie(s) as a Zend object. | |
const | COOKIE_STRING_ARRAY = 1 |
Return cookie(s) as a string (suitable for sending in an HTTP request) | |
const | COOKIE_STRING_CONCAT = 2 |
Return all cookies as one long string (suitable for sending in an HTTP request) | |
const | COOKIE_STRING_CONCAT_STRICT = 3 |
Return all cookies as one long string (strict mode) | |
Protected Member Functions | |
_flattenCookiesArray ($ptr, $retAs=self::COOKIE_OBJECT) | |
Helper function to recursively flatten an array. | |
_matchDomain ($domain) | |
Return a subset of the cookies array matching a specific domain. | |
_matchPath ($domains, $path) | |
Return a subset of a domain-matching cookies that also match a specified path. | |
Protected Member Functions inherited from Headers | |
lazyLoadHeader ($index) | |
Protected Attributes | |
$cookies = [] | |
$headers = null | |
$rawCookies | |
Protected Attributes inherited from Headers | |
$pluginClassLoader = null | |
$headersKeys = [] | |
$headers = [] | |
Additional Inherited Members | |
Static Protected Member Functions inherited from Headers | |
static | createKey ($name) |
Create array key from header name. | |
A Zend object is designed to contain and maintain HTTP cookies, and should be used along with Zend in order to manage cookies across HTTP requests and responses.
The class contains an array of Zend 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 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::COOKIE_STRING_ARRAY) or one unified string for all cookies (by passing Zend::COOKIE_STRING_CONCAT).
|
protected |
Helper function to recursively flatten an array.
Should be used when exporting the cookies array (or parts of it)
\Zend\Http\Header\SetCookie | array | $ptr | |
int | $retAs | What value to return |
|
protected |
Return a subset of the cookies array matching a specific domain.
string | $domain |
|
protected |
Return a subset of a domain-matching cookies that also match a specified path.
array | $domains | |
string | $path |
addCookie | ( | $cookie, | |
$refUri = null |
|||
) |
Add a cookie to the class.
Cookie should be passed either as a Zend object or as a string - in which case an object is created from the string.
SetCookie | string | $cookie | |
Uri\Uri | string | $refUri | Optional reference URI (for domain, path, secure) |
Exception\InvalidArgumentException |
addCookiesFromResponse | ( | Response | $response, |
$refUri | |||
) |
Parse an HTTP response, adding all the cookies set in that response.
Response | $response | |
Uri\Uri | string | $refUri | Requested URI |
|
static |
|
static |
Exception\RuntimeException |
$string |
getAllCookies | ( | $retAs = self::COOKIE_OBJECT | ) |
Get all cookies in the cookie jar as an array.
int | $retAs | Whether to return cookies as objects of or as strings |
getCookie | ( | $uri, | |
$cookieName, | |||
$retAs = self::COOKIE_OBJECT |
|||
) |
Get a specific cookie according to a URI and name.
Uri\Uri | string | $uri | The uri (domain and path) to match |
string | $cookieName | The cookie's name |
int | $retAs | Whether to return cookies as objects of or as strings |
Exception\InvalidArgumentException | if invalid URI specified or invalid $retAs value |
getMatchingCookies | ( | $uri, | |
$matchSessionCookies = true , |
|||
$retAs = self::COOKIE_OBJECT , |
|||
$now = null |
|||
) |
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.
string | Uri\Uri | $uri | URI to check against (secure, domain, path) |
bool | $matchSessionCookies | Whether to send session cookies |
int | $retAs | Whether to return cookies as objects of or as strings |
int | $now | Override the current time when checking for expiry time |
Exception\InvalidArgumentException | if invalid URI specified |
isEmpty | ( | ) |
Tells if the array of cookies is empty.
reset | ( | ) |
Empties the cookieJar of any cookie.
|
protected |
|
protected |
|
protected |
const COOKIE_OBJECT = 0 |
Return cookie(s) as a Zend object.
const COOKIE_STRING_ARRAY = 1 |
Return cookie(s) as a string (suitable for sending in an HTTP request)
const COOKIE_STRING_CONCAT = 2 |
Return all cookies as one long string (suitable for sending in an HTTP request)
const COOKIE_STRING_CONCAT_STRICT = 3 |
Return all cookies as one long string (strict mode)