8000 Merge branch '3.3' into 3.4 · symfony/symfony@eaeb820 · GitHub
[go: up one dir, main page]

Skip to content

Commit eaeb820

Browse files
Merge branch '3.3' into 3.4
* 3.3: [HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
2 parents e7cfaa9 + ed52036 commit eaeb820

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
@@ -100,6 +100,12 @@ class NativeSessionStorage implements SessionStorageInterface
100100
*/
101101
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
102102
{
103+
$this->setMetadataBag($metaBag);
104+
105+
if (\PHP_SESSION_ACTIVE === session_status()) {
106+
return;
107+
}
108+
103109
$options += array(
104110
'cache_limiter' => 'private_no_expire',
105111
'cache_expire' => 0,
@@ -109,7 +115,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
109115

110116
session_register_shutdown();
111117

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

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

Lines changed: 20 additions & 0 deletions
< 3F5E td data-grid-cell-id="diff-e0c3a6a9578bc93c09ea6bffc926c96dd7322bfccacd7d3c28596d7ea23fde0c-244-264-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
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