Definition at line 60 of file CookieJar.php.
◆ __construct()
◆ _flattenCookiesArray()
_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
-
- Returns
- array|string
Definition at line 288 of file CookieJar.php.
289 if (is_array($ptr)) {
291 foreach ($ptr as
$item) {
292 if ($ret_as == self::COOKIE_STRING_CONCAT_STRICT) {
293 $postfix_combine = (!is_array(
$item) ?
' ' :
'');
295 }
elseif ($ret_as == self::COOKIE_STRING_CONCAT) {
305 return array($ptr->__toString());
312 return $ptr->__toString();
elseif(isset( $params[ 'redirect_parent']))
_flattenCookiesArray($ptr, $ret_as=self::COOKIE_OBJECT)
const COOKIE_STRING_CONCAT
const COOKIE_STRING_ARRAY
const COOKIE_STRING_CONCAT_STRICT
◆ _matchDomain()
Return a subset of the cookies array matching a specific domain
- Parameters
-
- Returns
- array
Definition at line 331 of file CookieJar.php.
335 foreach (array_keys($this->cookies) as $cdom) {
337 $ret[$cdom] = $this->cookies[$cdom];
static matchCookieDomain($cookieDomain, $host)
◆ _matchPath()
_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
Definition at line 351 of file CookieJar.php.
355 foreach ($domains as $dom => $paths_array) {
356 foreach (array_keys($paths_array) as $cpath) {
358 if (! isset($ret[$dom])) {
359 $ret[$dom] = array();
362 $ret[$dom][$cpath] = $paths_array[$cpath];
static matchCookiePath($cookiePath, $path)
◆ addCookie()
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_uri | Optional reference URI (for domain, path, secure) |
boolean | $encodeValue | |
Definition at line 128 of file CookieJar.php.
130 if (is_string($cookie)) {
135 $domain = $cookie->getDomain();
136 $path = $cookie->getPath();
137 if (! isset($this->cookies[$domain])) $this->cookies[$domain] = array();
138 if (! isset($this->cookies[$domain][
$path])) $this->cookies[$domain][
$path] = array();
139 $this->cookies[$domain][
$path][$cookie->getName()] = $cookie;
140 $this->_rawCookies[] = $cookie;
142 #require_once 'Zend/Http/Exception.php'; 143 throw new Zend_Http_Exception(
'Supplient argument is not a valid cookie string or object');
static fromString($cookieStr, $refUri=null, $encodeValue=true)
◆ addCookiesFromResponse()
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_uri | Requested URI |
boolean | $encodeValue | |
Definition at line 155 of file CookieJar.php.
158 #require_once 'Zend/Http/Exception.php'; 163 $cookie_hdrs =
$response->getHeader(
'Set-Cookie');
165 if (is_array($cookie_hdrs)) {
166 foreach ($cookie_hdrs as $cookie) {
167 $this->
addCookie($cookie, $ref_uri, $encodeValue);
169 }
elseif (is_string($cookie_hdrs)) {
170 $this->
addCookie($cookie_hdrs, $ref_uri, $encodeValue);
elseif(isset( $params[ 'redirect_parent']))
addCookie($cookie, $ref_uri=null, $encodeValue=true)
◆ count()
Required by Countable interface
- Returns
- int
Definition at line 393 of file CookieJar.php.
395 return count($this->_rawCookies);
◆ fromResponse()
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 | $response | HTTP Response object |
Zend_Uri_Http | string | $uri | The requested URI |
- Returns
- Zend_Http_CookieJar
- Todo:
- Add the $uri functionality.
Definition at line 381 of file CookieJar.php.
384 $jar->addCookiesFromResponse(
$response, $ref_uri);
◆ getAllCookies()
getAllCookies |
( |
|
$ret_as = self::COOKIE_OBJECT | ) |
|
Get all cookies in the cookie jar as an array
- Parameters
-
int | $ret_as | Whether to return cookies as objects of Zend_Http_Cookie or as strings |
- Returns
- array|string
Definition at line 180 of file CookieJar.php.
183 if($ret_as == self::COOKIE_STRING_CONCAT_STRICT) {
_flattenCookiesArray($ptr, $ret_as=self::COOKIE_OBJECT)
◆ getCookie()
getCookie |
( |
|
$uri, |
|
|
|
$cookie_name, |
|
|
|
$ret_as = self::COOKIE_OBJECT |
|
) |
| |
Get a specific cookie according to a URI and name
- Parameters
-
Zend_Uri_Http | string | $uri | The uri (domain and path) to match |
string | $cookie_name | The cookie's name |
int | $ret_as | Whether to return cookies as objects of Zend_Http_Cookie or as strings |
- Returns
- Zend_Http_Cookie|string
Definition at line 237 of file CookieJar.php.
239 if (is_string($uri)) {
243 if (! $uri instanceof Zend_Uri_Http) {
244 #require_once 'Zend/Http/Exception.php'; 249 $path = $uri->getPath();
253 if (isset($this->cookies[$uri->getHost()][
$path][$cookie_name])) {
254 $cookie = $this->cookies[$uri->getHost()][
$path][$cookie_name];
262 return rtrim(trim($cookie->__toString()),
';');
267 return $cookie->__toString();
271 #require_once 'Zend/Http/Exception.php'; static factory($uri='http', $className=null)
const COOKIE_STRING_CONCAT
const COOKIE_STRING_ARRAY
const COOKIE_STRING_CONCAT_STRICT
◆ getIterator()
Required by IteratorAggregate interface
- Returns
- ArrayIterator
Definition at line 403 of file CookieJar.php.
405 return new ArrayIterator($this->_rawCookies);
◆ getMatchingCookies()
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 | $uri | URI to check against (secure, domain, path) |
boolean | $matchSessionCookies | Whether to send session cookies |
int | $ret_as | Whether to return cookies as objects of Zend_Http_Cookie or as strings |
int | $now | Override the current time when checking for expiry time |
- Returns
- array|string
Definition at line 200 of file CookieJar.php.
204 if (! $uri instanceof Zend_Uri_Http) {
205 #require_once 'Zend/Http/Exception.php'; 217 if ($cookie->match($uri, $matchSessionCookies, $now))
222 if($ret_as == self::COOKIE_STRING_CONCAT_STRICT) {
223 $ret = rtrim(trim($ret),
';');
static factory($uri='http', $className=null)
_flattenCookiesArray($ptr, $ret_as=self::COOKIE_OBJECT)
_matchPath($domains, $path)
◆ isEmpty()
Tells if the jar is empty of any cookie
- Returns
- bool
Definition at line 413 of file CookieJar.php.
415 return count($this) == 0;
◆ reset()
◆ $_rawCookies
◆ $cookies
◆ COOKIE_OBJECT
◆ COOKIE_STRING_ARRAY
const COOKIE_STRING_ARRAY = 1 |
Return cookie(s) as a string (suitable for sending in an HTTP request)
Definition at line 72 of file CookieJar.php.
◆ COOKIE_STRING_CONCAT
const COOKIE_STRING_CONCAT = 2 |
Return all cookies as one long string (suitable for sending in an HTTP request)
Definition at line 78 of file CookieJar.php.
◆ COOKIE_STRING_CONCAT_STRICT
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
Definition at line 85 of file CookieJar.php.
The documentation for this class was generated from the following file: