201. Class

201.1. Zend\Http\Client\Cookies

A 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 ZendHttpHeaderCookie 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 ZendHttpHeaderCookie 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 ZendHttpClientCookies::COOKIE_STRING_ARRAY) or one unified string for all cookies (by passing ZendHttpClientCookies::COOKIE_STRING_CONCAT).

201.1.1. Methods

201.1.1.1. addCookie

addCookie()

Add a cookie to the class. Cookie should be passed either as a ZendHttpHeaderCookie object or as a string - in which case an object is created from the string.

Parameters:
  • SetCookie|string
  • UriUri|string – Optional reference URI (for domain, path, secure)
Throws ExceptionInvalidArgumentException:
 

if invalid $cookie value

201.1.1.2. addCookiesFromResponse

addCookiesFromResponse()

Parse an HTTP response, adding all the cookies set in that response

Parameters:
  • Response
  • UriUri|string – Requested URI

201.1.1.3. getAllCookies

getAllCookies()

Get all cookies in the cookie jar as an array

Parameters:int – Whether to return cookies as objects of ZendHttpHeaderCookie or as strings
Return type:array|string

201.1.1.4. getMatchingCookies

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.

Parameters:
  • string|UriUri – URI to check against (secure, domain, path)
  • bool – Whether to send session cookies
  • int – Whether to return cookies as objects of ZendHttpHeaderCookie or as strings
  • int – Override the current time when checking for expiry time
Throws ExceptionInvalidArgumentException:
 

if invalid URI

Return type:

array|string

201.1.1.5. getCookie

getCookie()

Get a specific cookie according to a URI and name

Parameters:
  • UriUri|string – The uri (domain and path) to match
  • string – The cookie’s name
  • int – Whether to return cookies as objects of ZendHttpHeaderCookie or as strings
Throws ExceptionInvalidArgumentException:
 

if invalid URI specified or invalid $retAs value

Return type:

Cookie|string

201.1.1.6. _flattenCookiesArray

_flattenCookiesArray()

Helper function to recursively flatten an array. Should be used when exporting the cookies array (or parts of it)

Parameters:
  • ZendHttpHeaderCookie|array
  • int – What value to return
Return type:

array|string

201.1.1.7. _matchDomain

_matchDomain()

Return a subset of the cookies array matching a specific domain

Parameters:string
Return type:array

201.1.1.8. _matchPath

_matchPath()

Return a subset of a domain-matching cookies that also match a specified path

Parameters:
  • array
  • string
Return type:

array

201.1.1.9. fromResponse

fromResponse()

Create a new Cookies object and automatically load into it all the cookies set in an Http_Response object. If $uri is set, it will be considered as the requested URI for setting default domain and path of the cookie.

Parameters:
  • Response – HTTP Response object
  • UriUri|string – The requested URI
Return type:

Cookies

Todo :

201.1.1.10. count

count()

Required by Countable interface

Return type:int

201.1.1.11. getIterator

getIterator()

Required by IteratorAggregate interface

Return type:ArrayIterator

201.1.1.12. isEmpty

isEmpty()

Tells if the array of cookies is empty

Return type:bool

201.1.1.13. reset

reset()

Empties the cookieJar of any cookie

Return type:Cookies

201.1.1.14. offsetExists

offsetExists()

(PHP 5 &gt;= 5.1.0)<br/> Whether a offset exists

Parameters:mixed – <p>

An offset to check for. </p>

rtype:bool Returns true on success or false on failure.

</p> <p> The return value will be casted to boolean if non-boolean was returned.

201.1.1.15. offsetGet

offsetGet()

(PHP 5 &gt;= 5.1.0)<br/> Offset to retrieve

Parameters:mixed – <p>

The offset to retrieve. </p>

rtype:mixed Can return all value types.

201.1.1.16. offsetSet

offsetSet()

(PHP 5 &gt;= 5.1.0)<br/> Offset to set

Parameters:mixed – <p>

The offset to assign the value to. </p>

param mixed:<p>

The value to set. </p>

rtype:void

201.1.1.17. offsetUnset

offsetUnset()

(PHP 5 &gt;= 5.1.0)<br/> Offset to unset

Parameters:mixed – <p>

The offset to unset. </p>

rtype:void

201.1.1.18. serialize

serialize()

(PHP 5 &gt;= 5.1.0)<br/> String representation of object

Return type:string the string representation of the object or &null;

201.1.1.19. unserialize

unserialize()

(PHP 5 &gt;= 5.1.0)<br/> Constructs the object

Parameters:string – <p>

The string representation of the object. </p>

rtype:mixed the original value unserialized.

201.1.1.20. fromArray

fromArray()

201.1.1.21. fromString

fromString()

201.1.1.22. toArray

toArray()

201.1.1.23. toString

toString()

201.1.1.24. get

get()

201.1.1.25. set

set()

201.1.2. Constants