Ver Fonte

merged branch martinmayer/session_saving (PR #1937)

Commits
-------

34a1b53 [HttpFoundation] Do not save session in Session::__destroy() when saved already

Discussion
----------

[HttpFoundation] Saving session data in __destroy() has a side effect on functional tests

Having functional test with several non-insulated requests, TestSessionListener invokes session saving at the end of every request. But instance of Session remains in memory until it's collected by garbage collector which saves the same data again in __destroy() method. The problem is that session object can get collected after other requests changed session data (e. g. user logged in) resulting in former data overwriting the latter.
Fabien Potencier há 14 anos atrás
pai
commit
a5ccda47b4
1 ficheiros alterados com 4 adições e 1 exclusões
  1. 4 1
      src/Symfony/Component/HttpFoundation/Session.php

+ 4 - 1
src/Symfony/Component/HttpFoundation/Session.php

@@ -29,6 +29,7 @@ class Session implements \Serializable
     protected $oldFlashes;
     protected $locale;
     protected $defaultLocale;
+    protected $saved;
 
     /**
      * Constructor.
@@ -46,6 +47,7 @@ class Session implements \Serializable
         $this->attributes = array();
         $this->setPhpDefaultLocale($this->defaultLocale);
         $this->started = false;
+        $this->saved = false;
     }
 
     /**
@@ -356,11 +358,12 @@ class Session implements \Serializable
             'flashes'    => $this->flashes,
             'locale'     => $this->locale,
         ));
+        $this->saved = true;
     }
 
     public function __destruct()
     {
-        if (true === $this->started) {
+        if (true === $this->started && !$this->saved) {
             $this->save();
         }
     }