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

Skip to content

[HttpFoundation] Just skip PHP's session_set_save_handler, not the full setSaveHandler #24946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ class NativeSessionStorage implements SessionStorageInterface
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
{
$this->setMetadataBag($metaBag);
$this->setSaveHandler($handler);

if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
if (!$this->canUpdatePhpSession()) {
return;
}

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

$this->setOptions($options);
$this->setSaveHandler($handler);
}

/**
Expand Down Expand Up @@ -408,7 +408,7 @@ public function setSaveHandler($saveHandler = null)
}
$this->saveHandler = $saveHandler;

if ($this->saveHandler instanceof \SessionHandlerInterface) {
if ($this->saveHandler instanceof \SessionHandlerInterface && $this->canUpdatePhpSession()) {
if (\PHP_VERSION_ID >= 50400) {
session_set_save_handler($this->saveHandler, false);
} else {
Expand Down Expand Up @@ -449,4 +449,14 @@ protected function loadSession(array &$session = null)
$this->started = true;
$this->closed = false;
}

/**
* Return true if we can update PHP's session.
*
* @return bool
*/
private function canUpdatePhpSession()
{
return \PHP_VERSION_ID <= 50400 || \PHP_SESSION_ACTIVE !== session_status();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,19 @@ public function testSetSessionOptionsOnceSessionStartedIsIgnored()
// Assert no exception has been thrown by `getStorage()`
$this->addToAssertionCount(1);
}

/**
* @requires PHP 5.4
*/
public function testGetBagsOnceSessionStartedIsIgnored()
{
session_start();
$bag = new AttributeBag();
$bag->setName('flashes');

$storage = $this->getStorage();
$storage->registerBag($bag);

$this->assertEquals($storage->getBag('flashes'), $bag);
}
}