123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace Symfony\Component\HttpFoundation\Session\Storage;
- use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
- class MetadataBag implements SessionBagInterface
- {
- public const CREATED = 'c';
- public const UPDATED = 'u';
- public const LIFETIME = 'l';
-
- private $name = '__metadata';
-
- private $storageKey;
-
- protected $meta = [self::CREATED => 0, self::UPDATED => 0, self::LIFETIME => 0];
-
- private $lastUsed;
-
- private $updateThreshold;
-
- public function __construct(string $storageKey = '_sf2_meta', int $updateThreshold = 0)
- {
- $this->storageKey = $storageKey;
- $this->updateThreshold = $updateThreshold;
- }
-
- 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();
- }
- }
-
- public function getLifetime()
- {
- return $this->meta[self::LIFETIME];
- }
-
- public function stampNew(?int $lifetime = null)
- {
- $this->stampCreated($lifetime);
- }
-
- public function getStorageKey()
- {
- return $this->storageKey;
- }
-
- public function getCreated()
- {
- return $this->meta[self::CREATED];
- }
-
- public function getLastUsed()
- {
- return $this->lastUsed;
- }
-
- public function clear()
- {
-
- return null;
- }
-
- public function getName()
- {
- return $this->name;
- }
-
- public function setName(string $name)
- {
- $this->name = $name;
- }
- private function stampCreated(?int $lifetime = null): void
- {
- $timeStamp = time();
- $this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp;
- $this->meta[self::LIFETIME] = $lifetime ?? (int) \ini_get('session.cookie_lifetime');
- }
- }
|