8000 Just skip PHP's `session_set_save_handler`, not the full `setSaveHand… · symfony/symfony@5cada3a · GitHub
[go: up one dir, main page]

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

Appearance settings

Commit 5cada3a

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

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ class NativeSessionStorage implements SessionStorageInterface
103103
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
104104
{
105105
$this->setMetadataBag($metaBag);
106+
$this->setSaveHandler($handler);
106107

107-
if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
108+
if (!$this->canUpdatePhpSession()) {
108109
return;
109110
}
110111

@@ -121,7 +122,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
121122
}
122123

123124
$this->setOptions($options);
124-
$this->setSaveHandler($handler);
125125
}
126126

127127
/**
@@ -408,7 +408,7 @@ public function setSaveHandler($saveHandler = null)
408408
}
409409
$this->saveHandler = $saveHandler;
410410

411-
if ($this->saveHandler instanceof \SessionHandlerInterface) {
411+
if ($this->saveHandler instanceof \SessionHandlerInterface && $this->canUpdatePhpSession()) {
412412
if (\PHP_VERSION_ID >= 50400) {
413413
session_set_save_handler($this->saveHandler, false);
414414
} else {
@@ -449,4 +449,14 @@ protected function loadSession(array &$session = null)
449449
$this->started = true;
450450
$this->closed = false;
451451
}
452+
453+
/**
454+
* Return true if we can update PHP's session.
455+
*
456+
* @return bool
457+
*/
458+
private function canUpdatePhpSession()
459+
{
460+
return \PHP_VERSION_ID <= 50400 || \PHP_SESSION_ACTIVE !== session_status();
461+
}
452462
}

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)
0