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

Skip to content

Commit c49af5c

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

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,16 @@ 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

114+
111115
$options += array(
112116
// disable by default because it's managed by HeaderBag (if used)
113117
'cache_limiter' => '',
@@ -121,7 +125,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
121125
}
122126

123127
$this->setOptions($options);
124-
$this->setSaveHandler($handler);
125128
}
126129

127130
/**
@@ -383,10 +386,11 @@ public function setOptions(array $options)
383386
* @see http://github.com/drak/NativeSession
384387
*
385388
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler
389+
* @param bool $updatePhpHandler
386390
*
387391
* @throws \InvalidArgumentException
388392
*/
389-
public function setSaveHandler($saveHandler = null)
393+
public function setSaveHandler($saveHandler = null, bool $updatePhpHandler = true)
390394
{
391395
if (!$saveHandler instanceof AbstractProxy &&
392396
!$saveHandler instanceof NativeSessionHandler &&
@@ -408,7 +412,7 @@ public function setSaveHandler($saveHandler = null)
408412
}
409413
$this->saveHandler = $saveHandler;
410414

411-
if ($this->saveHandler instanceof \SessionHandlerInterface) {
415+
if ($this->saveHandler instanceof \SessionHandlerInterface && $updatePhpHandler) {
412416
if (\PHP_VERSION_ID >= 50400) {
413417
session_set_save_handler($this->saveHandler, false);
414418
} 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)