From f096ac1d95bfe5fa75396ad9b6e20ee871aeb0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Sat, 18 Mar 2023 15:42:29 +0100 Subject: [PATCH] SessionExtension: don't set readAndClose if null (#213) 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). --- src/Bridges/HttpDI/SessionExtension.php | 4 ++++ src/Http/Session.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Bridges/HttpDI/SessionExtension.php b/src/Bridges/HttpDI/SessionExtension.php index f3d13b47..ed9fdf91 100644 --- a/src/Bridges/HttpDI/SessionExtension.php +++ b/src/Bridges/HttpDI/SessionExtension.php @@ -91,6 +91,10 @@ public function loadConfiguration() $options['autoStart'] = false; } + if ($config->readAndClose === null) { + unset($options['readAndClose']); + } + if (!empty($options)) { $session->addSetup('setOptions', [$options]); } diff --git a/src/Http/Session.php b/src/Http/Session.php index 87536242..a591f736 100644 --- a/src/Http/Session.php +++ b/src/Http/Session.php @@ -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.'); }