bug #24531 [HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2 (sroze)
This PR was merged into the 2.7 branch.
Discussion
----------
[HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #24524
| License | MIT
| Doc PR | ø
PHP 7.2 disallow setting session options when the session was already started. This PR will not set any option if the session is already started and throw an exception if trying to do so with custom options.
Commits
-------
00a1357
[HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
This commit is contained in:
commit
ff58ec865c
@ -102,6 +102,12 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
|
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(
|
$options += array(
|
||||||
// disable by default because it's managed by HeaderBag (if used)
|
// disable by default because it's managed by HeaderBag (if used)
|
||||||
'cache_limiter' => '',
|
'cache_limiter' => '',
|
||||||
@ -114,7 +120,6 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
register_shutdown_function('session_write_close');
|
register_shutdown_function('session_write_close');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setMetadataBag($metaBag);
|
|
||||||
$this->setOptions($options);
|
$this->setOptions($options);
|
||||||
$this->setSaveHandler($handler);
|
$this->setSaveHandler($handler);
|
||||||
}
|
}
|
||||||
|
@ -270,4 +270,30 @@ class NativeSessionStorageTest extends TestCase
|
|||||||
$this->assertSame($id, $storage->getId(), 'Same session ID after restarting');
|
$this->assertSame($id, $storage->getId(), 'Same session ID after restarting');
|
||||||
$this->assertSame(7, $storage->getBag('attributes')->get('lucky'), 'Data still available');
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user