Skip to content

Commit 23d917f

Browse files
srozenicolas-grekas
authored andcommitted
[HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
1 parent efb4891 commit 23d917f

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' => '',
@@ -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+
public function testCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
275+
{
276+
session_start();
277+
$this->getStorage();
278+
279+
// Assert no exception has been thrown by `getStorage()`
280+
$this->assertTrue(true);
281+
}
282+
283+
public function testSetSessionOptionsOnceSessionStartedIsIgnored()
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy