Properly merge session cookie_* parameters
Prefixed following session options: 'lifetime', 'path', 'domain', 'secure', 'httponly' because this results in better session driver code
This commit is contained in:
parent
3de31c62d6
commit
e0fba80057
@ -42,6 +42,8 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
|
|||||||
* added support for placeholders in route defaults and requirements (replaced by the value set in the service container)
|
* added support for placeholders in route defaults and requirements (replaced by the value set in the service container)
|
||||||
* added Filesystem component as a dependency
|
* added Filesystem component as a dependency
|
||||||
* added support for hinclude (use ``standalone: 'js'`` in render tag)
|
* added support for hinclude (use ``standalone: 'js'`` in render tag)
|
||||||
|
* [BC BREAK] following session options: 'lifetime', 'path', 'domain', 'secure', 'httponly'
|
||||||
|
are now prefixed with cookie_ when dumped to the container
|
||||||
|
|
||||||
### MonologBundle
|
### MonologBundle
|
||||||
|
|
||||||
|
@ -294,11 +294,17 @@ class FrameworkExtension extends Extension
|
|||||||
// session storage
|
// session storage
|
||||||
$container->setAlias('session.storage', $config['storage_id']);
|
$container->setAlias('session.storage', $config['storage_id']);
|
||||||
$options = array();
|
$options = array();
|
||||||
foreach (array('name', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'auto_start') as $key) {
|
foreach (array('name', 'auto_start') as $key) {
|
||||||
if (isset($config[$key])) {
|
if (isset($config[$key])) {
|
||||||
$options[$key] = $config[$key];
|
$options[$key] = $config[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//drivers require correct names for cookie options e.g the one with cookie_ prefix
|
||||||
|
foreach (array('lifetime', 'path', 'domain', 'secure', 'httponly') as $key) {
|
||||||
|
if (isset($config[$key])) {
|
||||||
|
$options['cookie_'.$key] = $config[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
$container->setParameter('session.storage.options', $options);
|
$container->setParameter('session.storage.options', $options);
|
||||||
|
|
||||||
$this->addClassesToCompile(array(
|
$this->addClassesToCompile(array(
|
||||||
|
@ -82,11 +82,11 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
|
|
||||||
$options = $container->getParameter('session.storage.options');
|
$options = $container->getParameter('session.storage.options');
|
||||||
$this->assertEquals('_SYMFONY', $options['name']);
|
$this->assertEquals('_SYMFONY', $options['name']);
|
||||||
$this->assertEquals(86400, $options['lifetime']);
|
$this->assertEquals(86400, $options['cookie_lifetime']);
|
||||||
$this->assertEquals('/', $options['path']);
|
$this->assertEquals('/', $options['cookie_path']);
|
||||||
$this->assertEquals('example.com', $options['domain']);
|
$this->assertEquals('example.com', $options['cookie_domain']);
|
||||||
$this->assertTrue($options['secure']);
|
$this->assertTrue($options['cookie_secure']);
|
||||||
$this->assertTrue($options['httponly']);
|
$this->assertTrue($options['cookie_httponly']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTemplating()
|
public function testTemplating()
|
||||||
|
@ -200,27 +200,20 @@ abstract class AbstractSessionStorage implements SessionStorageInterface
|
|||||||
*/
|
*/
|
||||||
protected function setOptions(array $options)
|
protected function setOptions(array $options)
|
||||||
{
|
{
|
||||||
$cookieDefaults = session_get_cookie_params();
|
$this->options = $options;
|
||||||
$this->options = array_merge(array(
|
|
||||||
'cookie_lifetime' => $cookieDefaults['lifetime'],
|
|
||||||
'cookie_path' => $cookieDefaults['path'],
|
|
||||||
'cookie_domain' => $cookieDefaults['domain'],
|
|
||||||
'cookie_secure' => $cookieDefaults['secure'],
|
|
||||||
'cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false,
|
|
||||||
), $options);
|
|
||||||
|
|
||||||
// Unless session.cache_limiter has been set explicitly, disable it
|
// set defaults for certain values
|
||||||
// because this is managed by HeaderBag directly (if used).
|
$defaults = array(
|
||||||
if (!isset($this->options['cache_limiter'])) {
|
'cache_limiter' => '', // disable by default because it's managed by HeaderBag (if used)
|
||||||
$this->options['cache_limiter'] = false;
|
'auto_start' => true,
|
||||||
|
'use_cookies' => true,
|
||||||
|
'cookie_httponly' => true,
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($defaults as $key => $value) {
|
||||||
|
if (!isset($this->options[$key])) {
|
||||||
|
$this->options[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->options['auto_start'])) {
|
|
||||||
$this->options['auto_start'] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->options['use_cookies'])) {
|
|
||||||
$this->options['use_cookies'] = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->options as $key => $value) {
|
foreach ($this->options as $key => $value) {
|
||||||
|
@ -56,9 +56,9 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @return AbstractSessionStorage
|
* @return AbstractSessionStorage
|
||||||
*/
|
*/
|
||||||
protected function getStorage()
|
protected function getStorage($options = array())
|
||||||
{
|
{
|
||||||
$storage = new CustomHandlerSessionStorage();
|
$storage = new CustomHandlerSessionStorage($options);
|
||||||
$storage->registerBag(new AttributeBag);
|
$storage->registerBag(new AttributeBag);
|
||||||
|
|
||||||
return $storage;
|
return $storage;
|
||||||
@ -139,4 +139,25 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
|
|||||||
$storage = new ConcreteSessionStorage(array('cache_limiter' => 'public'));
|
$storage = new ConcreteSessionStorage(array('cache_limiter' => 'public'));
|
||||||
$this->assertEquals('public', ini_get('session.cache_limiter'));
|
$this->assertEquals('public', ini_get('session.cache_limiter'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCookieOptions()
|
||||||
|
{
|
||||||
|
$options = array(
|
||||||
|
'cookie_lifetime' => 123456,
|
||||||
|
'cookie_path' => '/my/cookie/path',
|
||||||
|
'cookie_domain' => 'symfony2.example.com',
|
||||||
|
'cookie_secure' => true,
|
||||||
|
'cookie_httponly' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->getStorage($options);
|
||||||
|
$temp = session_get_cookie_params();
|
||||||
|
$gco = array();
|
||||||
|
|
||||||
|
foreach ($temp as $key => $value) {
|
||||||
|
$gco['cookie_'.$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($options, $gco);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user