$cookies
$cookies : array
Persists non-session cookies using a JSON formatted file
remove(string $domain = null, string $path = null, string $name = null) : \Guzzle\Plugin\Cookie\CookieJar\CookieJarInterface
Remove cookies currently held in the Cookie cookieJar.
Invoking this method without arguments will empty the whole Cookie cookieJar. If given a $domain argument only cookies belonging to that domain will be removed. If given a $domain and $path argument, cookies belonging to the specified path within that domain are removed. If given all three arguments, then the cookie with the specified name, path and domain is removed.
string | $domain | Set to clear only cookies matching a domain |
string | $path | Set to clear only cookies matching a domain and path |
string | $name | Set to clear only cookies matching a domain, path, and name |
removeTemporary() : \Guzzle\Plugin\Cookie\CookieJar\CookieJarInterface
Discard all temporary cookies.
Scans for all cookies in the cookieJar with either no expire field or a true discard flag. To be called when the user agent shuts down according to RFC 2965.
removeExpired() : \Guzzle\Plugin\Cookie\CookieJar\CookieJarInterface
Delete any expired cookies
all(string $domain = null, string $path = null, string $name = null, boolean $skipDiscardable = false, boolean $skipExpired = true) : array
Get all of the matching cookies
string | $domain | Domain of the cookie |
string | $path | Path of the cookie |
string | $name | Name of the cookie |
boolean | $skipDiscardable | Set to TRUE to skip cookies with the Discard attribute. |
boolean | $skipExpired | Set to FALSE to include expired |
Returns an array of Cookie objects
add(\Guzzle\Plugin\Cookie\Cookie $cookie) : boolean
Add a cookie to the cookie cookieJar
\Guzzle\Plugin\Cookie\Cookie | $cookie | Cookie to add |
Returns true on success or false on failure
addCookiesFromResponse(\Guzzle\Http\Message\Response $response, \Guzzle\Http\Message\RequestInterface $request = null)
Add cookies from a {@see Guzzle\Http\Message\Response} object
\Guzzle\Http\Message\Response | $response | Response object |
\Guzzle\Http\Message\RequestInterface | $request | Request that received the response |
getMatchingCookies(\Guzzle\Http\Message\RequestInterface $request) : array
Get cookies matching a request object
\Guzzle\Http\Message\RequestInterface | $request | Request object to match |
removeCookieIfEmpty(\Guzzle\Plugin\Cookie\Cookie $cookie)
If a cookie already exists and the server asks to set it again with a null value, the cookie must be deleted.
\Guzzle\Plugin\Cookie\Cookie | $cookie |
<?php
namespace Guzzle\Plugin\Cookie\CookieJar;
use Guzzle\Common\Exception\RuntimeException;
/**
* Persists non-session cookies using a JSON formatted file
*/
class FileCookieJar extends ArrayCookieJar
{
/** @var string filename */
protected $filename;
/**
* Create a new FileCookieJar object
*
* @param string $cookieFile File to store the cookie data
*
* @throws RuntimeException if the file cannot be found or created
*/
public function __construct($cookieFile)
{
$this->filename = $cookieFile;
$this->load();
}
/**
* Saves the file when shutting down
*/
public function __destruct()
{
$this->persist();
}
/**
* Save the contents of the data array to the file
*
* @throws RuntimeException if the file cannot be found or created
*/
protected function persist()
{
if (false === file_put_contents($this->filename, $this->serialize())) {
// @codeCoverageIgnoreStart
throw new RuntimeException('Unable to open file ' . $this->filename);
// @codeCoverageIgnoreEnd
}
}
/**
* Load the contents of the json formatted file into the data array and discard any unsaved state
*/
protected function load()
{
$json = file_get_contents($this->filename);
if (false === $json) {
// @codeCoverageIgnoreStart
throw new RuntimeException('Unable to open file ' . $this->filename);
// @codeCoverageIgnoreEnd
}
$this->unserialize($json);
$this->cookies = $this->cookies ?: array();
}
}