Skip to content

Commit 5a2627d

Browse files
authored
Merge pull request #10 from tflori/feature-destroyEmpty
add option not to destroy empty sessions
2 parents f58f6cc + bd3e8e8 commit 5a2627d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/SessionInstance.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class SessionInstance implements SessionInterface
1414
* @var bool */
1515
protected static $useCookies;
1616

17+
/** Weather or not an empty session should be destroyed
18+
* @var bool */
19+
public $destroyEmptySession = true;
20+
1721
/** Whether the session has been started or not.
1822
* @var bool $init */
1923
protected $init = false;
@@ -152,7 +156,7 @@ protected function updateSession(array $data = [])
152156
if ($val === null) {
153157
unset($_SESSION[$key]);
154158
// destroy the session when empty
155-
if (empty($_SESSION)) {
159+
if (empty($_SESSION) && $this->destroyEmptySession) {
156160
$this->destroy();
157161
return;
158162
}

tests/DeleteTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function doesNotWriteWhenNothingDeleted()
6767
}
6868

6969
/** @test */
70-
public function destorysTheSessionWhenLastKeyGotDeleted()
70+
public function destroysTheSessionWhenLastKeyGotDeleted()
7171
{
7272
$session = new SessionInstance('session');
7373
$session->set('foo', 'bar');
@@ -76,4 +76,16 @@ public function destorysTheSessionWhenLastKeyGotDeleted()
7676

7777
$session->delete('foo');
7878
}
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+
}
7991
}

0 commit comments

Comments
 (0)