@@ -68,8 +68,11 @@ public function __construct(string $name) {
6868 * @param integer $value
6969 */
7070 public function set (string $ key , $ value ) {
71- $ this ->validateSession ();
71+ $ reopened = $ this ->reopen ();
7272 $ _SESSION [$ key ] = $ value ;
73+ if ($ reopened ) {
74+ $ this ->close ();
75+ }
7376 }
7477
7578 /**
@@ -101,6 +104,7 @@ public function remove(string $key) {
101104 }
102105
103106 public function clear () {
107+ $ this ->reopen ();
104108 $ this ->invoke ('session_unset ' );
105109 $ this ->regenerateId ();
106110 $ this ->startSession (true );
@@ -120,6 +124,7 @@ public function close() {
120124 * @return void
121125 */
122126 public function regenerateId (bool $ deleteOldSession = true , bool $ updateToken = false ) {
127+ $ this ->reopen ();
123128 $ oldId = null ;
124129
125130 if ($ updateToken ) {
@@ -171,8 +176,14 @@ public function getId(): string {
171176 /**
172177 * @throws \Exception
173178 */
174- public function reopen () {
175- throw new \Exception ('The session cannot be reopened - reopen() is only to be used in unit testing. ' );
179+ public function reopen (): bool {
180+ if ($ this ->sessionClosed ) {
181+ $ this ->startSession (false , false );
182+ $ this ->sessionClosed = false ;
183+ return true ;
184+ }
185+
186+ return false ;
176187 }
177188
178189 /**
@@ -214,7 +225,11 @@ private function invoke(string $functionName, array $parameters = [], bool $sile
214225 }
215226 }
216227
217- private function startSession (bool $ silence = false ) {
218- $ this ->invoke ('session_start ' , [['cookie_samesite ' => 'Lax ' ]], $ silence );
228+ private function startSession (bool $ silence = false , bool $ readAndClose = true ) {
229+ $ sessionParams = ['cookie_samesite ' => 'Lax ' ];
230+ if (\OC ::hasSessionRelaxedExpiry ()) {
231+ $ sessionParams ['read_and_close ' ] = $ readAndClose ;
232+ }
233+ $ this ->invoke ('session_start ' , [$ sessionParams ], $ silence );
219234 }
220235}
0 commit comments