Skip to content

[HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2 #24531

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

Merged
merged 1 commit into from
Nov 5, 2017
Merged
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 @@ -102,6 +102,12 @@ class NativeSessionStorage implements SessionStorageInterface
*/
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
{
$this->setMetadataBag($metaBag);

if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
return;
}

$options += array(
// disable by default because it's managed by HeaderBag (if used)
'cache_limiter' => '',
Expand All @@ -114,7 +120,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
register_shutdown_function('session_write_close');
}

$this->setMetadataBag($metaBag);
$this->setOptions($options);
$this->setSaveHandler($handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,30 @@ public function testRestart()
$this->assertSame($id, $storage->getId(), 'Same session ID after restarting');
$this->assertSame(7, $storage->getBag('attributes')->get('lucky'), 'Data still available');
}

/**
* @requires PHP 5.4
*/
public function testCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
{
session_start();
$this->getStorage();

// Assert no exception has been thrown by `getStorage()`
$this->addToAssertionCount(1);
}

/**
* @requires PHP 5.4
*/
public function testSetSessionOptionsOnceSessionStartedIsIgnored()
{
session_start();
$this->getStorage(array(
'name' => 'something-else',
));

// Assert no exception has been thrown by `getStorage()`
$this->addToAssertionCount(1);
}
}