Skip to content

Commit f94b3e7

Browse files
Merge branch '6.4' into 7.4
* 6.4: [HttpFoundation] Fix session cookie_lifetime not applied in mock session storage [Serializer] Fix denormalization of magic `__set` properties Add 'sms' to hostless schemes
2 parents fd97d5e + cffffd0 commit f94b3e7

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Session/Storage/MetadataBag.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

Tests/Session/Storage/MetadataBagTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)