diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index bd045b8c64..cf5e813c83 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -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 Filesystem component as a dependency * 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 diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index f8c499b205..bf170acb01 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -294,11 +294,17 @@ class FrameworkExtension extends Extension // session storage $container->setAlias('session.storage', $config['storage_id']); $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])) { $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); $this->addClassesToCompile(array( diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 5ef967a647..087ec3eb8b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -82,11 +82,11 @@ abstract class FrameworkExtensionTest extends TestCase $options = $container->getParameter('session.storage.options'); $this->assertEquals('_SYMFONY', $options['name']); - $this->assertEquals(86400, $options['lifetime']); - $this->assertEquals('/', $options['path']); - $this->assertEquals('example.com', $options['domain']); - $this->assertTrue($options['secure']); - $this->assertTrue($options['httponly']); + $this->assertEquals(86400, $options['cookie_lifetime']); + $this->assertEquals('/', $options['cookie_path']); + $this->assertEquals('example.com', $options['cookie_domain']); + $this->assertTrue($options['cookie_secure']); + $this->assertTrue($options['cookie_httponly']); } public function testTemplating() diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/AbstractSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/AbstractSessionStorage.php index 9fcabab593..31e4ce43d4 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/AbstractSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/AbstractSessionStorage.php @@ -200,28 +200,21 @@ abstract class AbstractSessionStorage implements SessionStorageInterface */ protected function setOptions(array $options) { - $cookieDefaults = session_get_cookie_params(); - $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); + $this->options = $options; - // Unless session.cache_limiter has been set explicitly, disable it - // because this is managed by HeaderBag directly (if used). - if (!isset($this->options['cache_limiter'])) { - $this->options['cache_limiter'] = false; - } + // set defaults for certain values + $defaults = array( + 'cache_limiter' => '', // disable by default because it's managed by HeaderBag (if used) + 'auto_start' => true, + 'use_cookies' => true, + 'cookie_httponly' => true, + ); - if (!isset($this->options['auto_start'])) { - $this->options['auto_start'] = 0; - } - - if (!isset($this->options['use_cookies'])) { - $this->options['use_cookies'] = 1; - } + foreach ($defaults as $key => $value) { + if (!isset($this->options[$key])) { + $this->options[$key] = $value; + } + } foreach ($this->options as $key => $value) { if (in_array($key, array( diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/AbstractSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/AbstractSessionStorageTest.php index d442e8a70b..8d53002c8d 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/AbstractSessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/AbstractSessionStorageTest.php @@ -56,9 +56,9 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase /** * @return AbstractSessionStorage */ - protected function getStorage() + protected function getStorage($options = array()) { - $storage = new CustomHandlerSessionStorage(); + $storage = new CustomHandlerSessionStorage($options); $storage->registerBag(new AttributeBag); return $storage; @@ -139,4 +139,25 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase $storage = new ConcreteSessionStorage(array('cache_limiter' => 'public')); $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); + } }