Skip to content

Commit

Permalink
SessionExtension: don't set readAndClose if null (#213)
Browse files Browse the repository at this point in the history
Session class throws exception if session is started and option read_and_close is set.
SessionExtension breaks compatibility with other session implementations (in case they already started the session) by always setting that option (to default value).
  • Loading branch information
mabar authored and dg committed Mar 18, 2023
1 parent d6ef402 commit f096ac1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Bridges/HttpDI/SessionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public function loadConfiguration()
$options['autoStart'] = false;
}

if ($config->readAndClose === null) {
unset($options['readAndClose']);
}

if (!empty($options)) {
$session->addSetup('setOptions', [$options]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function setOptions(array $options)
$normalized[$normKey] = $value;
}

if (array_key_exists('read_and_close', $normalized)) {
if (isset($normalized['read_and_close'])) {
if (session_status() === PHP_SESSION_ACTIVE) {
throw new Nette\InvalidStateException('Cannot configure "read_and_close" for already started session.');
}
Expand Down

0 comments on commit f096ac1

Please sign in to comment.