class SessionCookieJar in Auth0 Single Sign On 8.2
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 persist 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) {
parent::__construct();
$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() {
if (!isset($_SESSION[$this->sessionKey])) {
return;
}
$data = json_decode($_SESSION[$this->sessionKey], 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 | function | Finds and returns the cookie based on the name | |
CookieJar:: |
private | function | Computes cookie path following RFC 6265 section 5.1.4 | |
CookieJar:: |
public static | function | ||
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 persist 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 |