class MetadataBag in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/http-foundation/Session/Storage/MetadataBag.php \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag
- 8 core/lib/Drupal/Core/Session/MetadataBag.php \Drupal\Core\Session\MetadataBag
Same name and namespace in other branches
- 8.0 vendor/symfony/http-foundation/Session/Storage/MetadataBag.php \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag
Metadata container.
Adds metadata to the session.
@author Drak <drak@zikula.org>
Hierarchy
- class \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag implements SessionBagInterface
Expanded class hierarchy of MetadataBag
3 files declare their use of MetadataBag
- MetadataBag.php in core/
lib/ Drupal/ Core/ Session/ MetadataBag.php - Contains \Drupal\Core\Session\MetadataBag.
- MetadataBagTest.php in vendor/
symfony/ http-foundation/ Tests/ Session/ Storage/ MetadataBagTest.php - SessionInterface.php in vendor/
symfony/ http-foundation/ Session/ SessionInterface.php
File
- vendor/
symfony/ http-foundation/ Session/ Storage/ MetadataBag.php, line 23
Namespace
Symfony\Component\HttpFoundation\Session\StorageView source
class MetadataBag implements SessionBagInterface {
const CREATED = 'c';
const UPDATED = 'u';
const LIFETIME = 'l';
/**
* @var string
*/
private $name = '__metadata';
/**
* @var string
*/
private $storageKey;
/**
* @var array
*/
protected $meta = array(
self::CREATED => 0,
self::UPDATED => 0,
self::LIFETIME => 0,
);
/**
* Unix timestamp.
*
* @var int
*/
private $lastUsed;
/**
* @var int
*/
private $updateThreshold;
/**
* Constructor.
*
* @param string $storageKey The key used to store bag in the session.
* @param int $updateThreshold The time to wait between two UPDATED updates
*/
public function __construct($storageKey = '_sf2_meta', $updateThreshold = 0) {
$this->storageKey = $storageKey;
$this->updateThreshold = $updateThreshold;
}
/**
* {@inheritdoc}
*/
public function initialize(array &$array) {
$this->meta =& $array;
if (isset($array[self::CREATED])) {
$this->lastUsed = $this->meta[self::UPDATED];
$timeStamp = time();
if ($timeStamp - $array[self::UPDATED] >= $this->updateThreshold) {
$this->meta[self::UPDATED] = $timeStamp;
}
}
else {
$this
->stampCreated();
}
}
/**
* Gets the lifetime that the session cookie was set with.
*
* @return int
*/
public function getLifetime() {
return $this->meta[self::LIFETIME];
}
/**
* Stamps a new session's metadata.
*
* @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
* will leave the system settings unchanged, 0 sets the cookie
* to expire with browser session. Time is in seconds, and is
* not a Unix timestamp.
*/
public function stampNew($lifetime = null) {
$this
->stampCreated($lifetime);
}
/**
* {@inheritdoc}
*/
public function getStorageKey() {
return $this->storageKey;
}
/**
* Gets the created timestamp metadata.
*
* @return int Unix timestamp
*/
public function getCreated() {
return $this->meta[self::CREATED];
}
/**
* Gets the last used metadata.
*
* @return int Unix timestamp
*/
public function getLastUsed() {
return $this->lastUsed;
}
/**
* {@inheritdoc}
*/
public function clear() {
// nothing to do
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->name;
}
/**
* Sets name.
*
* @param string $name
*/
public function setName($name) {
$this->name = $name;
}
private function stampCreated($lifetime = null) {
$timeStamp = time();
$this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp;
$this->meta[self::LIFETIME] = null === $lifetime ? ini_get('session.cookie_lifetime') : $lifetime;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MetadataBag:: |
private | property | Unix timestamp. | |
MetadataBag:: |
protected | property | ||
MetadataBag:: |
private | property | ||
MetadataBag:: |
private | property | ||
MetadataBag:: |
private | property | ||
MetadataBag:: |
public | function |
Clears out data from bag. Overrides SessionBagInterface:: |
|
MetadataBag:: |
constant | |||
MetadataBag:: |
public | function | Gets the created timestamp metadata. | |
MetadataBag:: |
public | function | Gets the last used metadata. | |
MetadataBag:: |
public | function | Gets the lifetime that the session cookie was set with. | |
MetadataBag:: |
public | function |
Gets this bag's name. Overrides SessionBagInterface:: |
|
MetadataBag:: |
public | function |
Gets the storage key for this bag. Overrides SessionBagInterface:: |
|
MetadataBag:: |
public | function |
Initializes the Bag. Overrides SessionBagInterface:: |
|
MetadataBag:: |
constant | |||
MetadataBag:: |
public | function | Sets name. | |
MetadataBag:: |
private | function | ||
MetadataBag:: |
public | function | Stamps a new session's metadata. | |
MetadataBag:: |
constant | |||
MetadataBag:: |
public | function | Constructor. | 1 |