Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 488bc8b

Browse files
committed
[Session] added "delete" method to Session and NativeSessionStorage
1 parent b2e7ca3 commit 488bc8b

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/Symfony/Component/HttpFoundation/Session/Session.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ public function invalidate($lifetime = null)
167167
return $this->migrate(true, $lifetime);
168168
}
169169

170+
/**
171+
* {@inheritdoc}
172+
*/
173+
public function destroy()
174+
{
175+
return $this->storage->destroy();
176+
}
177+
170178
/**
171179
* {@inheritdoc}
172180
*/

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,34 @@ public function regenerate($destroy = false, $lifetime = null)
209209
return session_regenerate_id($destroy);
210210
}
211211

212+
/**
213+
* {@inheritdoc}
214+
*/
215+
public function destroy()
216+
{
217+
$this->clean();
218+
219+
if (ini_get("session.use_cookies")) {
220+
221+
if (headers_sent($file, $line)) {
222+
throw new \RuntimeException(sprintf('Failed to destroy the session because headers have already been sent by "%s" at line %d.', $file, $line));
223+
}
224+
225+
$params = session_get_cookie_params();
226+
setcookie(session_name(), '', time() - 42000,
227+
$params["path"], $params["domain"],
228+
$params["secure"], $params["httponly"]
229+
);
230+
}
231+
232+
$ret = session_destroy();
233+
234+
$this->closed = true;
235+
$this->started = false;
236+
237+
return $ret;
238+
}
239+
212240
/**
213241
* {@inheritdoc}
214242
*/
@@ -230,13 +258,7 @@ public function save()
230258
*/
231259
public function clear()
232260
{
233-
// clear out the bags
234-
foreach ($this->bags as $bag) {
235-
$bag->clear();
236-
}
237-
238-
// clear out the session
239-
$_SESSION = array();
261+
$this->clean();
240262

241263
// reconnect the bags to the session
242264
$this->loadSession();
@@ -387,6 +409,20 @@ public function setSaveHandler($saveHandler = null)
387409
}
388410
}
389411

412+
/**
413+
* {@inheritdoc}
414+
*/
415+
protected function clean()
416+
{
417+
// clear out the bags
418+
foreach ($this->bags as $bag) {
419+
$bag->clear();
420+
}
421+
422+
// clear out the session
423+
$_SESSION = array();
424+
}
425+
390426
/**
391427
* Load the session with attributes.
392428
*

0 commit comments

Comments
 (0)