Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b93d835

Browse files
committed
Just skip PHP's session_set_save_handler, not the full setSaveHandler method
1 parent 99f8d85 commit b93d835

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ class NativeSessionStorage implements SessionStorageInterface
102102
*/
103103
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
104104
{
105+
$cannotOverrideSessionParameters = \PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status();
106+
105107
$this->setMetadataBag($metaBag);
108+
$this->setSaveHandler($handler, !$cannotOverrideSessionParameters);
106109

107-
if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
110+
if ($cannotOverrideSessionParameters) {
108111
return;
109112
}
110113

@@ -121,7 +124,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
121124
}
122125

123126
$this->setOptions($options);
124-
$this->setSaveHandler($handler);
125127
}
126128

127129
/**
@@ -383,10 +385,11 @@ public function setOptions(array $options)
383385
* @see http://github.com/drak/NativeSession
384386
*
385387
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler
388+
* @param bool $updatePhpHandler
386389
*
387390
* @throws \InvalidArgumentException
388391
*/
389-
public function setSaveHandler($saveHandler = null)
392+
public function setSaveHandler($saveHandler = null, bool $updatePhpHandler = true)
390393
{
391394
if (!$saveHandler instanceof AbstractProxy &&
392395
!$saveHandler instanceof NativeSessionHandler &&
@@ -408,7 +411,7 @@ public function setSaveHandler($saveHandler = null)
408411
}
409412
$this->saveHandler = $saveHandler;
410413

411-
if ($this->saveHandler instanceof \SessionHandlerInterface) {
414+
if ($this->saveHandler instanceof \SessionHandlerInterface && $updatePhpHandler) {
412415
if (\PHP_VERSION_ID >= 50400) {
413416
session_set_save_handler($this->saveHandler, false);
414417
} else {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,19 @@ public function testSetSessionOptionsOnceSessionStartedIsIgnored()
296296
// Assert no exception has been thrown by `getStorage()`
297297
$this->addToAssertionCount(1);
298298
}
299+
300+
/**
301+
* @requires PHP 5.4
302+
*/
303+
public function testGetBagsOnceSessionStartedIsIgnored()
304+
{
305+
session_start();
306+
$bag = new AttributeBag();
307+
$bag->setName('flashes');
308+
309+
$storage = $this->getStorage();
310+
$storage->registerBag($bag);
311+
312+
$this->assertEquals($storage->getBag('flashes'), $bag);
313+
}
299314
}

0 commit comments

Comments
 (0)