10000 Merge branch '3.4' · symfony/symfony@8e5b3b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e5b3b1

Browse files
Merge branch '3.4'
* 3.4: [HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
2 parents 1c5eeb5 + eaeb820 commit 8e5b3b1

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
@@ -96,6 +96,12 @@ class NativeSessionStorage implements SessionStorageInterface
9696
*/
9797
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
9898
{
99+
$this->setMetadataBag($metaBag);
100+
101+
if (\PHP_SESSION_ACTIVE === session_status()) {
102+
return;
103+
}
104+
99105
$options += array(
100106
'cache_limiter' => 'private_no_expire',
101107
'cache_expire' => 0,
@@ -106,7 +112,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
106112

107113
session_register_shutdown();
108114

109-
$this->setMetadataBag($metaBag);
110115
$this->setOptions($options);
111116
$this->setSaveHandler($handler);
112117
}

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)
0