diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 652531d613300..627a7e814fdc8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -167,6 +167,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode) ->canBeUnset() ->children() ->booleanNode('auto_start')->defaultFalse()->end() + ->booleanNode('auto_extend')->defaultFalse()->end() ->scalarNode('storage_id')->defaultValue('session.storage.native')->end() ->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end() ->scalarNode('name')->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 8c91c37a4e3b4..e061a7d568cfe 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -295,7 +295,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c // session storage $container->setAlias('session.storage', $config['storage_id']); $options = array(); - foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'auto_start') as $key) { + foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'auto_start' , 'auto_extend') as $key) { if (isset($config[$key])) { $options[$key] = $config[$key]; } diff --git a/src/Symfony/Component/HttpFoundation/Session/Session.php b/src/Symfony/Component/HttpFoundation/Session/Session.php index 13c6448874a3a..a208afb2dbdba 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Session.php +++ b/src/Symfony/Component/HttpFoundation/Session/Session.php @@ -71,7 +71,12 @@ public function __construct(SessionStorageInterface $storage = null, AttributeBa */ public function start() { - return $this->storage->start(); + $couldStart = $this->storage->start(); + if ($couldStart && $this->storage->getAutoExtend()) { + $this->migrate(); + } + + return $couldStart; } /** diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php index 6f1e279f41654..8ad1fe9dabb42 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php @@ -37,6 +37,11 @@ class MockArraySessionStorage implements SessionStorageInterface */ protected $name; + /** + * @var boolean + */ + protected $autoExtend; + /** * @var boolean */ @@ -191,6 +196,14 @@ public function getBag($name) return $this->bags[$name]; } + /** + * {@inheritdoc} + */ + public function getAutoExtend() + { + return $this->autoExtend; + } + /** * Generates a session ID. * diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 5252bf55f2afc..7147ad4d5bf43 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -40,6 +40,11 @@ class NativeSessionStorage implements SessionStorageInterface */ protected $closed = false; + /** + * @var boolean + */ + protected $autoExtend = false; + /** * @var AbstractProxy */ @@ -56,6 +61,7 @@ class NativeSessionStorage implements SessionStorageInterface * but we omit 'session.' from the beginning of the keys for convenience. * * auto_start, "0" + * auto_extend, false * cache_limiter, "nocache" (use "0" to prevent headers from being sent entirely). * cookie_domain, "" * cookie_httponly, "" @@ -249,6 +255,14 @@ public function getBag($name) return $this->bags[$name]; } + /** + * {@inheritdoc} + */ + public function getAutoExtend() + { + return $this->autoExtend; + } + /** * Sets session.* ini variables. * @@ -273,6 +287,8 @@ public function setOptions(array $options) 'upload_progress.cleanup', 'upload_progress.prefix', 'upload_progress.name', 'upload_progress.freq', 'upload_progress.min-freq', 'url_rewriter.tags'))) { ini_set('session.'.$key, $value); + } elseif ('auto_extend' == $key) { + $this->autoExtend = $value; } } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php b/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php index 8bf2e5d32ad02..fd372759dfcf7 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php @@ -123,4 +123,11 @@ function getBag($name); * @param SessionBagInterface $bag */ function registerBag(SessionBagInterface $bag); + + /** + * Returns if the session should be automatically extended on start + * + * @return Boolean True if automatic extension is needed, false if not + */ + function getAutoExtend(); }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: