Open Journal Systems  3.3.0
vendor/symfony/http-foundation/Session/Storage/MetadataBag.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
15 
23 class MetadataBag implements SessionBagInterface
24 {
25  const CREATED = 'c';
26  const UPDATED = 'u';
27  const LIFETIME = 'l';
28 
32  private $name = '__metadata';
33 
37  private $storageKey;
38 
42  protected $meta = [self::CREATED => 0, self::UPDATED => 0, self::LIFETIME => 0];
43 
49  private $lastUsed;
50 
54  private $updateThreshold;
55 
60  public function __construct(string $storageKey = '_sf2_meta', int $updateThreshold = 0)
61  {
62  $this->storageKey = $storageKey;
63  $this->updateThreshold = $updateThreshold;
64  }
65 
69  public function initialize(array &$array)
70  {
71  $this->meta = &$array;
72 
73  if (isset($array[self::CREATED])) {
74  $this->lastUsed = $this->meta[self::UPDATED];
75 
76  $timeStamp = time();
77  if ($timeStamp - $array[self::UPDATED] >= $this->updateThreshold) {
78  $this->meta[self::UPDATED] = $timeStamp;
79  }
80  } else {
81  $this->stampCreated();
82  }
83  }
84 
90  public function getLifetime()
91  {
92  return $this->meta[self::LIFETIME];
93  }
94 
103  public function stampNew($lifetime = null)
104  {
105  $this->stampCreated($lifetime);
106  }
107 
111  public function getStorageKey()
112  {
113  return $this->storageKey;
114  }
115 
121  public function getCreated()
122  {
123  return $this->meta[self::CREATED];
124  }
125 
131  public function getLastUsed()
132  {
133  return $this->lastUsed;
134  }
135 
139  public function clear()
140  {
141  // nothing to do
142  }
143 
147  public function getName()
148  {
149  return $this->name;
150  }
151 
157  public function setName($name)
158  {
159  $this->name = $name;
160  }
161 
162  private function stampCreated(int $lifetime = null): void
163  {
164  $timeStamp = time();
165  $this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp;
166  $this->meta[self::LIFETIME] = (null === $lifetime) ? ini_get('session.cookie_lifetime') : $lifetime;
167  }
168 }
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\$meta
$meta
Definition: lib/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:51
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\stampNew
stampNew($lifetime=null)
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:118
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\UPDATED
const UPDATED
Definition: lib/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:26
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\getLifetime
getLifetime()
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:105
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\setName
setName($name)
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:172
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\clear
clear()
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:154
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\getLastUsed
getLastUsed()
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:146
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\getStorageKey
getStorageKey()
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:126
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\LIFETIME
const LIFETIME
Definition: lib/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:27
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\CREATED
const CREATED
Definition: lib/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:25
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\getCreated
getCreated()
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:136
Symfony\Component\HttpFoundation\Session\SessionBagInterface
Definition: lib/vendor/symfony/http-foundation/Session/SessionBagInterface.php:19
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\__construct
__construct($storageKey='_sf2_meta', $updateThreshold=0)
Definition: lib/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:77
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\getName
getName()
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:162
Symfony\Component\HttpFoundation\Session\Storage
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\initialize
initialize(array &$array)
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:84
Symfony\Component\HttpFoundation\Session\Storage\MetadataBag\__construct
__construct(string $storageKey='_sf2_meta', int $updateThreshold=0)
Definition: vendor/symfony/http-foundation/Session/Storage/MetadataBag.php:75