File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ class SessionInstance implements SessionInterface
14
14
* @var bool */
15
15
protected static $ useCookies ;
16
16
17
+ /** Weather or not an empty session should be destroyed
18
+ * @var bool */
19
+ public $ destroyEmptySession = true ;
20
+
17
21
/** Whether the session has been started or not.
18
22
* @var bool $init */
19
23
protected $ init = false ;
@@ -152,7 +156,7 @@ protected function updateSession(array $data = [])
152
156
if ($ val === null ) {
153
157
unset($ _SESSION [$ key ]);
154
158
// destroy the session when empty
155
- if (empty ($ _SESSION )) {
159
+ if (empty ($ _SESSION ) && $ this -> destroyEmptySession ) {
156
160
$ this ->destroy ();
157
161
return ;
158
162
}
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ public function doesNotWriteWhenNothingDeleted()
67
67
}
68
68
69
69
/** @test */
70
- public function destorysTheSessionWhenLastKeyGotDeleted ()
70
+ public function destroysTheSessionWhenLastKeyGotDeleted ()
71
71
{
72
72
$ session = new SessionInstance ('session ' );
73
73
$ session ->set ('foo ' , 'bar ' );
@@ -76,4 +76,16 @@ public function destorysTheSessionWhenLastKeyGotDeleted()
76
76
77
77
$ session ->delete ('foo ' );
78
78
}
79
+
80
+ /** @test */
81
+ public function doesNotDestroyWhenConfigured ()
82
+ {
83
+ $ session = new SessionInstance ('session ' );
84
+ $ session ->set ('foo ' , 'bar ' );
85
+ $ session ->destroyEmptySession = false ;
86
+
87
+ $ this ->sessionHandler ->shouldNotReceive ('destroy ' );
88
+
89
+ $ session ->delete ('foo ' );
90
+ }
79
91
}
You can’t perform that action at this time.
0 commit comments