From 93e28cd91a4201f5298f7193cfabb1de2011f149 Mon Sep 17 00:00:00 2001 From: martiros Date: Tue, 20 Jan 2015 20:24:04 +0400 Subject: [PATCH] Do not call terminate method if handle method not called --- src/Illuminate/Session/Middleware/StartSession.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Session/Middleware/StartSession.php b/src/Illuminate/Session/Middleware/StartSession.php index d62993a28f75..bf4579be6e98 100644 --- a/src/Illuminate/Session/Middleware/StartSession.php +++ b/src/Illuminate/Session/Middleware/StartSession.php @@ -20,6 +20,12 @@ class StartSession implements MiddlewareContract, TerminableMiddleware { */ protected $manager; + /** + * True if handle method called + * @var bool + */ + protected $sessionHandled = false; + /** * Create a new session middleware. * @@ -40,6 +46,7 @@ public function __construct(SessionManager $manager) */ public function handle($request, Closure $next) { + $this->sessionHandled = true; // If a session driver has been configured, we will need to start the session here // so that the data is ready for an application. Note that the Laravel sessions // do not make use of PHP "native" sessions in any way since they are crappy. @@ -76,7 +83,7 @@ public function handle($request, Closure $next) */ public function terminate($request, $response) { - if ($this->sessionConfigured() && ! $this->usingCookieSessions()) + if ($this->sessionHandled && $this->sessionConfigured() && ! $this->usingCookieSessions()) { $this->manager->driver()->save(); }