Skip to content

[WIP][Session] Added auto-extend capability #3654

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Component/HttpFoundation/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class MockArraySessionStorage implements SessionStorageInterface
*/
protected $name;

/**
* @var boolean
*/
protected $autoExtend;

/**
* @var boolean
*/
Expand Down Expand Up @@ -191,6 +196,14 @@ public function getBag($name)
return $this->bags[$name];
}

/**
* {@inheritdoc}
*/
public function getAutoExtend()
{
return $this->autoExtend;
}

/**
* Generates a session ID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class NativeSessionStorage implements SessionStorageInterface
*/
protected $closed = false;

/**
* @var boolean
*/
protected $autoExtend = false;

/**
* @var AbstractProxy
*/
Expand All @@ -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, ""
Expand Down Expand Up @@ -249,6 +255,14 @@ public function getBag($name)
return $this->bags[$name];
}

/**
* {@inheritdoc}
*/
public function getAutoExtend()
{
return $this->autoExtend;
}

/**
* Sets session.* ini variables.
*
Expand All @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}