@@ -53,6 +53,9 @@ class Session
5353 /** @var \SessionHandlerInterface */
5454 private $ handler ;
5555
56+ /** @var bool */
57+ private $ readAndClose = false ;
58+
5659
5760 public function __construct (IRequest $ request , IResponse $ response )
5861 {
@@ -90,7 +93,7 @@ public function start(): void
9093
9194 try {
9295 // session_start returns false on failure only sometimes
93- Nette \Utils \Callback::invokeSafe ('session_start ' , [], function (string $ message ) use (&$ e ): void {
96+ Nette \Utils \Callback::invokeSafe ('session_start ' , [[ ' read_and_close ' => $ this -> readAndClose ] ], function (string $ message ) use (&$ e ): void {
9497 $ e = new Nette \InvalidStateException ($ message );
9598 });
9699 } catch (\Exception $ e ) {
@@ -329,6 +332,13 @@ public function setOptions(array $options)
329332 $ key = strtolower (preg_replace ('#(.)(?=[A-Z])# ' , '$1_ ' , $ key )); // camelCase -> snake_case
330333 $ normalized [$ key ] = $ value ;
331334 }
335+ if (!empty ($ normalized ['read_and_close ' ])) {
336+ if (session_status () === PHP_SESSION_ACTIVE ) {
337+ throw new Nette \InvalidStateException ('Cannot configure "read_and_close" for already started session. ' );
338+ }
339+ $ this ->readAndClose = (bool ) $ normalized ['read_and_close ' ];
340+ unset($ normalized ['read_and_close ' ]);
341+ }
332342 if (session_status () === PHP_SESSION_ACTIVE ) {
333343 $ this ->configure ($ normalized );
334344 }
0 commit comments