class SessionCookieJar in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php \GuzzleHttp\Cookie\SessionCookieJar
Persists cookies in the client session
Hierarchy
- class \GuzzleHttp\Cookie\CookieJar implements CookieJarInterface
- class \GuzzleHttp\Cookie\SessionCookieJar
Expanded class hierarchy of SessionCookieJar
File
- vendor/
guzzlehttp/ guzzle/ src/ Cookie/ SessionCookieJar.php, line 7
Namespace
GuzzleHttp\CookieView source
class SessionCookieJar extends CookieJar {
/** @var string session key */
private $sessionKey;
/** @var bool Control whether to presist session cookies or not. */
private $storeSessionCookies;
/**
* Create a new SessionCookieJar object
*
* @param string $sessionKey Session key name to store the cookie
* data in session
* @param bool $storeSessionCookies Set to true to store session cookies
* in the cookie jar.
*/
public function __construct($sessionKey, $storeSessionCookies = false) {
$this->sessionKey = $sessionKey;
$this->storeSessionCookies = $storeSessionCookies;
$this
->load();
}
/**
* Saves cookies to session when shutting down
*/
public function __destruct() {
$this
->save();
}
/**
* Save cookies to the client session
*/
public function save() {
$json = [];
foreach ($this as $cookie) {
/** @var SetCookie $cookie */
if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) {
$json[] = $cookie
->toArray();
}
}
$_SESSION[$this->sessionKey] = json_encode($json);
}
/**
* Load the contents of the client session into the data array
*/
protected function load() {
$cookieJar = isset($_SESSION[$this->sessionKey]) ? $_SESSION[$this->sessionKey] : null;
$data = json_decode($cookieJar, true);
if (is_array($data)) {
foreach ($data as $cookie) {
$this
->setCookie(new SetCookie($cookie));
}
}
elseif (strlen($data)) {
throw new \RuntimeException("Invalid cookie data");
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CookieJar:: |
private | property | @var SetCookie[] Loaded cookie data | |
CookieJar:: |
private | property | @var bool | |
CookieJar:: |
public | function |
Remove cookies currently held in the cookie jar. Overrides CookieJarInterface:: |
|
CookieJar:: |
public | function |
Discard all sessions cookies. Overrides CookieJarInterface:: |
|
CookieJar:: |
public | function | ||
CookieJar:: |
public | function |
Extract cookies from an HTTP response and store them in the CookieJar. Overrides CookieJarInterface:: |
|
CookieJar:: |
public static | function | Create a new Cookie jar from an associative array and domain. | |
CookieJar:: |
public static | function | Quote the cookie value if it is not already quoted and it contains problematic characters. | |
CookieJar:: |
public | function | ||
CookieJar:: |
private | function | If a cookie already exists and the server asks to set it again with a null value, the cookie must be deleted. | |
CookieJar:: |
public | function |
Sets a cookie in the cookie jar. Overrides CookieJarInterface:: |
|
CookieJar:: |
public static | function | Evaluate if this cookie should be persisted to storage that survives between requests. | |
CookieJar:: |
public | function |
Converts the cookie jar to an array. Overrides CookieJarInterface:: |
|
CookieJar:: |
public | function |
Create a request with added cookie headers. Overrides CookieJarInterface:: |
|
SessionCookieJar:: |
private | property | @var string session key | |
SessionCookieJar:: |
private | property | @var bool Control whether to presist session cookies or not. | |
SessionCookieJar:: |
protected | function | Load the contents of the client session into the data array | |
SessionCookieJar:: |
public | function | Save cookies to the client session | |
SessionCookieJar:: |
public | function |
Create a new SessionCookieJar object Overrides CookieJar:: |
|
SessionCookieJar:: |
public | function | Saves cookies to session when shutting down |