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

Skip to content
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
Just skip PHP's session_set_save_handler, not the full `setSaveHand…
…ler` method
  • Loading branch information
sroze committed Nov 13, 2017
commit 5cada3afef60ede1364aa9d4217e41b57f8ab79b
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);
}
}