Zend Framework  1.12
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Http_CookieJar Class Reference

Public Member Functions

 __construct ()
 Construct a new CookieJar object.
 
 addCookie ($cookie, $ref_uri=null, $encodeValue=true)
 Add a cookie to the jar.
 
 addCookiesFromResponse ($response, $ref_uri, $encodeValue=true)
 Parse an HTTP response, adding all the cookies set in that response to the cookie jar.
 
 getAllCookies ($ret_as=self::COOKIE_OBJECT)
 Get all cookies in the cookie jar as an array.
 
 getMatchingCookies ($uri, $matchSessionCookies=true, $ret_as=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, $cookie_name, $ret_as=self::COOKIE_OBJECT)
 Get a specific cookie according to a URI and name.
 
 count ()
 Required by Countable interface.
 
 getIterator ()
 Required by IteratorAggregate interface.
 
 isEmpty ()
 Tells if the jar is empty of any cookie.
 
 reset ()
 Empties the cookieJar of any cookie.
 

Static Public Member Functions

static fromResponse (Zend_Http_Response $response, $ref_uri)
 Create a new CookieJar object and automatically load into it all the cookies set in an Http_Response object.
 

Public Attributes

const COOKIE_OBJECT = 0
 Return cookie(s) as a Zend_Http_Cookie 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, $ret_as=self::COOKIE_OBJECT)
 Helper function to recursivly 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 Attributes

 $cookies = array()
 
 $_rawCookies = array()
 

Constructor & Destructor Documentation

__construct ( )

Construct a new CookieJar object.

Member Function Documentation

_flattenCookiesArray (   $ptr,
  $ret_as = self::COOKIE_OBJECT 
)
protected

Helper function to recursivly flatten an array.

Shoud be used when exporting the cookies array (or parts of it)

Parameters
Zend_Http_Cookie | array$ptr
int$ret_asWhat value to return
Returns
array|string
_matchDomain (   $domain)
protected

Return a subset of the cookies array matching a specific domain.

Parameters
string$domain
Returns
array
_matchPath (   $domains,
  $path 
)
protected

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

Parameters
array$dom_array
string$path
Returns
array
addCookie (   $cookie,
  $ref_uri = null,
  $encodeValue = true 
)

Add a cookie to the jar.

Cookie should be passed either as a Zend_Http_Cookie object or as a string - in which case an object is created from the string.

Parameters
Zend_Http_Cookie | string$cookie
Zend_Uri_Http | string$ref_uriOptional reference URI (for domain, path, secure)
boolean$encodeValue
addCookiesFromResponse (   $response,
  $ref_uri,
  $encodeValue = true 
)

Parse an HTTP response, adding all the cookies set in that response to the cookie jar.

Parameters
Zend_Http_Response$response
Zend_Uri_Http | string$ref_uriRequested URI
boolean$encodeValue
count ( )

Required by Countable interface.

Returns
int
static fromResponse ( Zend_Http_Response  $response,
  $ref_uri 
)
static

Create a new CookieJar 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
Zend_Http_Response$responseHTTP Response object
Zend_Uri_Http | string$uriThe requested URI
Returns
Zend_Http_CookieJar
Todo:
Add the $uri functionality.
getAllCookies (   $ret_as = self::COOKIE_OBJECT)

Get all cookies in the cookie jar as an array.

Parameters
int$ret_asWhether to return cookies as objects of Zend_Http_Cookie or as strings
Returns
array|string
getCookie (   $uri,
  $cookie_name,
  $ret_as = self::COOKIE_OBJECT 
)

Get a specific cookie according to a URI and name.

Parameters
Zend_Uri_Http | string$uriThe uri (domain and path) to match
string$cookie_nameThe cookie's name
int$ret_asWhether to return cookies as objects of Zend_Http_Cookie or as strings
Returns
Zend_Http_Cookie|string
getIterator ( )

Required by IteratorAggregate interface.

Returns
ArrayIterator
getMatchingCookies (   $uri,
  $matchSessionCookies = true,
  $ret_as = 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.

Parameters
string | Zend_Uri_Http$uriURI to check against (secure, domain, path)
boolean$matchSessionCookiesWhether to send session cookies
int$ret_asWhether to return cookies as objects of Zend_Http_Cookie or as strings
int$nowOverride the current time when checking for expiry time
Returns
array|string
isEmpty ( )

Tells if the jar is empty of any cookie.

Returns
bool
reset ( )

Empties the cookieJar of any cookie.

Returns
Zend_Http_CookieJar

Member Data Documentation

$_rawCookies = array()
protected
$cookies = array()
protected
const COOKIE_OBJECT = 0

Return cookie(s) as a Zend_Http_Cookie 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)

  • Single space after the semi-colon separating each cookie
  • Remove trailing semi-colon, if any