Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit23d917f

Browse files
srozenicolas-grekas
authored andcommitted
[HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
1 parentefb4891 commit23d917f

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
publicfunction__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' =>'',
@@ -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‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,24 @@ 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+
publicfunctiontestCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
275+
{
276+
session_start();
277+
$this->getStorage();
278+
279+
// Assert no exception has been thrown by `getStorage()`
280+
$this->assertTrue(true);
281+
}
282+
283+
publicfunctiontestSetSessionOptionsOnceSessionStartedIsIgnored()
284+
{
285+
session_start();
286+
$this->getStorage(array(
287+
'name' =>'something-else',
288+
));
289+
290+
// Assert no exception has been thrown by `getStorage()`
291+
$this->assertTrue(true);
292+
}
273293
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp