Skip to content

Commit ed52036

Browse files
Merge branch '2.8' into 3.3
* 2.8: [HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
2 parents 024bfa4 + 9ca5069 commit ed52036

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines 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_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' => '',
@@ -110,7 +116,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
110116

111117
session_register_shutdown();
112118

113-
$this->setMetadataBag($metaBag);
114119
$this->setOptions($options);
115120
$this->setSaveHandler($handler);
116121
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,24 @@ public function testRestart()
242242
$this->assertSame($id, $storage->getId(), 'Same session ID after restarting');
243243
$this->assertSame(7, $storage->getBag('attributes')->get('lucky'), 'Data still available');
244244
}
245+
246+
public function testCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
247+
{
248+
session_start();
249+
$this->getStorage();
250+
251+
// Assert no exception has been thrown by `getStorage()`
252+
$this->addToAssertionCount(1);
253+
}
254+
255+
public function testSetSessionOptionsOnceSessionStartedIsIgnored()
256+
{
257+
session_start();
258+
$this->getStorage(array(
259+
'name' => 'something-else',
260+
));
261+
262+
// Assert no exception has been thrown by `getStorage()`
263+
$this->addToAssertionCount(1);
264+
}
245265
}

0 commit comments

Comments
 (0)