Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 00a1357

Browse filesBrowse files
srozenicolas-grekas
authored andcommitted
[HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
1 parent efb4891 commit 00a1357
Copy full SHA for 00a1357

File tree

2 files changed

+32
-1
lines changed
Filter options

2 files changed

+32
-1
lines changed

‎src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ class NativeSessionStorage implements SessionStorageInterface
102102
*/
103103
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
104104
{
105+
$this->setMetadataBag($metaBag);
106+
107+
if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
108+
return;
109+
}
110+
105111
$options += array(
106112
// disable by default because it's managed by HeaderBag (if used)
107113
'cache_limiter' => '',
@@ -114,7 +120,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
114120
register_shutdown_function('session_write_close');
115121
}
116122

117-
$this->setMetadataBag($metaBag);
118123
$this->setOptions($options);
119124
$this->setSaveHandler($handler);
120125
}

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,30 @@ public function testRestart()
270270
$this->assertSame($id, $storage->getId(), 'Same session ID after restarting');
271271
$this->assertSame(7, $storage->getBag('attributes')->get('lucky'), 'Data still available');
272272
}
273+
274+
/**
275+
* @requires PHP 5.4
276+
*/
277+
public function testCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
278+
{
279+
session_start();
280+
$this->getStorage();
281+
282+
// Assert no exception has been thrown by `getStorage()`
283+
$this->addToAssertionCount(1);
284+
}
285+
286+
/**
287+
* @requires PHP 5.4
288+
*/
289+
public function testSetSessionOptionsOnceSessionStartedIsIgnored()
290+
{
291+
session_start();
292+
$this->getStorage(array(
293+
'name' => 'something-else',
294+
));
295+
296+
// Assert no exception has been thrown by `getStorage()`
297+
$this->addToAssertionCount(1);
298+
}
273299
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.