Http/CookieJar.php

Show: PublicProtectedPrivateinherited
Table of Contents
Zend Framework
LICENSE This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Http  
Subpackage
CookieJar  
Version
$Id$  

\Zend_Http_CookieJar

Package: Zend_Http\CookieJar
A Zend_Http_CookieJar 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_Cookie objects. Cookies can be added to the jar automatically from a request or manually. Then, the jar 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_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_CookieJar::COOKIE_STRING_ARRAY) or one unified string for all cookies (by passing Zend_Http_CookieJar::COOKIE_STRING_CONCAT).
Implements
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Link
for some specs.  

Constants

>VConstant  COOKIE_OBJECT = 0
Return cookie(s) as a Zend_Http_Cookie object
>VConstant  COOKIE_STRING_ARRAY = 1
Return cookie(s) as a string (suitable for sending in an HTTP request)
>VConstant  COOKIE_STRING_CONCAT = 2
Return all cookies as one long string (suitable for sending in an HTTP request)
>VConstant  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

Properties

>VPropertyprotectedarray $_rawCookies = array()
The Zend_Http_Cookie array
Default valuearray()Details
Type
array
>VPropertyprotectedarray $cookies = array()
Array storing cookies
Cookies are stored according to domain and path: $cookies + www.mydomain.com + / - cookie1 - cookie2 + /somepath - othercookie + www.otherdomain.net + / - alsocookie
Default valuearray()Details
Type
array

Methods

methodpublic__construct() : void

Construct a new CookieJar object

methodprotected_flattenCookiesArray(\Zend_Http_Cookie | array $ptr, int $ret_as = self::COOKIE_OBJECT) : array | string

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

Parameters
NameTypeDescription
$ptr\Zend_Http_Cookie | array
$ret_asint

What value to return

Returns
TypeDescription
array | string
methodprotected_matchDomain(string $domain) : array

Return a subset of the cookies array matching a specific domain

Parameters
NameTypeDescription
$domainstring
Returns
TypeDescription
array
methodprotected_matchPath( $domains, string $path) : array

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

Parameters
NameTypeDescription
$domains
$pathstring
Returns
TypeDescription
array
methodpublicaddCookie(\Zend_Http_Cookie | string $cookie, \Zend_Uri_Http | string $ref_uri = null, boolean $encodeValue = true) : void

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
NameTypeDescription
$cookie\Zend_Http_Cookie | string
$ref_uri\Zend_Uri_Http | string

Optional reference URI (for domain, path, secure)

$encodeValueboolean
methodpublicaddCookiesFromResponse(\Zend_Http_Response $response, \Zend_Uri_Http | string $ref_uri, boolean $encodeValue = true) : void

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

Parameters
NameTypeDescription
$response\Zend_Http_Response
$ref_uri\Zend_Uri_Http | string

Requested URI

$encodeValueboolean
methodpubliccount() : int

Required by Countable interface

Returns
TypeDescription
int
methodpublicfromResponse(\Zend_Http_Response $response,  $ref_uri) : \Zend_Http_CookieJar
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
NameTypeDescription
$response\Zend_Http_Response

HTTP Response object

$ref_uri
Returns
TypeDescription
\Zend_Http_CookieJar
Details
Todo
Add the $uri functionality.  
methodpublicgetAllCookies(int $ret_as = self::COOKIE_OBJECT) : array | string

Get all cookies in the cookie jar as an array

Parameters
NameTypeDescription
$ret_asint

Whether to return cookies as objects of Zend_Http_Cookie or as strings

Returns
TypeDescription
array | string
methodpublicgetCookie(\Zend_Uri_Http | string $uri, string $cookie_name, int $ret_as = self::COOKIE_OBJECT) : \Zend_Http_Cookie | string

Get a specific cookie according to a URI and name

Parameters
NameTypeDescription
$uri\Zend_Uri_Http | string

The uri (domain and path) to match

$cookie_namestring

The cookie's name

$ret_asint

Whether to return cookies as objects of Zend_Http_Cookie or as strings

Returns
TypeDescription
\Zend_Http_Cookie | string
methodpublicgetIterator() : \ArrayIterator

Required by IteratorAggregate interface

Returns
TypeDescription
\ArrayIterator
methodpublicgetMatchingCookies(string | \Zend_Uri_Http $uri, boolean $matchSessionCookies = true, int $ret_as = self::COOKIE_OBJECT, int $now = null) : array | 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.

Parameters
NameTypeDescription
$uristring | \Zend_Uri_Http

URI to check against (secure, domain, path)

$matchSessionCookiesboolean

Whether to send session cookies

$ret_asint

Whether to return cookies as objects of Zend_Http_Cookie or as strings

$nowint

Override the current time when checking for expiry time

Returns
TypeDescription
array | string
methodpublicisEmpty() : bool

Tells if the jar is empty of any cookie

Returns
TypeDescription
bool
methodpublicreset() : \Zend_Http_CookieJar

Empties the cookieJar of any cookie

Returns
TypeDescription
\Zend_Http_CookieJar
Documentation was generated by phpDocumentor 2.2.0 .