File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,12 +32,14 @@ class MetadataBag implements SessionBagInterface
3232 private int $ lastUsed ;
3333
3434 /**
35- * @param string $storageKey The key used to store bag in the session
36- * @param int $updateThreshold The time to wait between two UPDATED updates
35+ * @param string $storageKey The key used to store bag in the session
36+ * @param int $updateThreshold The time to wait between two UPDATED updates
37+ * @param int|null $cookieLifetime The configured cookie lifetime; null to read from php.ini
3738 */
3839 public function __construct (
3940 private string $ storageKey = '_sf2_meta ' ,
4041 private int $ updateThreshold = 0 ,
42+ private ?int $ cookieLifetime = null ,
4143 ) {
4244 }
4345
@@ -126,6 +128,6 @@ private function stampCreated(?int $lifetime = null): void
126128 {
127129 $ timeStamp = time ();
128130 $ this ->meta [self ::CREATED ] = $ this ->meta [self ::UPDATED ] = $ this ->lastUsed = $ timeStamp ;
129- $ this ->meta [self ::LIFETIME ] = $ lifetime ?? (int ) \ini_get ('session.cookie_lifetime ' );
131+ $ this ->meta [self ::LIFETIME ] = $ lifetime ?? $ this -> cookieLifetime ?? (int ) \ini_get ('session.cookie_lifetime ' );
130132 }
131133}
Original file line number Diff line number Diff line change @@ -134,4 +134,13 @@ public function testLifetimeIsInt()
134134
135135 $ this ->assertIsInt ($ bag ->getLifetime ());
136136 }
137+
138+ public function testCookieLifetimeFromConstructor ()
139+ {
140+ $ bag = new MetadataBag ('_sf2_meta ' , 0 , 60 );
141+ $ sessionMetadata = [];
142+ $ bag ->initialize ($ sessionMetadata );
143+
144+ $ this ->assertSame (60 , $ bag ->getLifetime ());
145+ }
137146}
You can’t perform that action at this time.
0 commit comments