Skip to content

Commit c5ecf7b

Browse files
Merge branch '7.4' into 8.0
* 7.4: [HttpFoundation] Fix session cookie_lifetime not applied in mock session storage [Validator] Fix test [Serializer] Fix denormalization of magic `__set` properties [Config] Fix NodeDefinition template to be covariant Add 'sms' to hostless schemes [Validator] Fix required options check when extending a constraint with a simplified constructor [Validator] Skip ExpressionLanguage requirement in When constraint for closure expressions [Cache] Add timeout and slot eviction to LockRegistry stampede prevention [Console] Fix OUTPUT_RAW corrupting binary content on Windows [Form] Fix session data contamination by non-serializable objects in form flow [Mime] Use shell_exec() instead of passthru() in FileBinaryMimeTypeGuesser [HttpClient] Fix streaming from CachingHttpClient [DoctrineBridge] Rename `_schema_subscriber_check` table to `schema_subscriber_check_` for Oracle compatibility [HttpClient] Fix CachingHttpClient compatibility with decorator clients on 304 responses [FrameworkBundle] Fix stale container after reboot in KernelTestCase [Form] Fix duplicate validation errors when ValidatorExtension is instantiated multiple times
2 parents 7745ff1 + f94b3e7 commit c5ecf7b

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)