22
33namespace YetAnotherWebStack \PhpMemcachedSession \Model ;
44
5- class Session implements YetAnotherWebStack \PhpMemcachedSession \Interfaces \Model {
5+ class Session implements \ YetAnotherWebStack \PhpMemcachedSession \Interfaces \Model {
66
77 /**
88 *
@@ -40,12 +40,18 @@ class Session implements YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model
4040 */
4141 protected $ logger ;
4242
43+ /**
44+ *
45+ * @var boolean
46+ */
47+ protected $ wasStored = false ;
48+
4349 /**
4450 *
4551 * @param string $sessionId
4652 * @param \YetAnotherWebStack\PhpMemcachedSession\Interfaces\Repository $repository
4753 */
48- protected function __construct ($ sessionId ,
54+ public function __construct ($ sessionId ,
4955 \YetAnotherWebStack \PhpMemcachedSession \Interfaces \Repository $ repository ,
5056 \Psr \Log \LoggerInterface $ logger ) {
5157 $ this ->logger = $ logger ;
@@ -67,7 +73,7 @@ protected function getKeys() {
6773 /**
6874 * stores the sessionId
6975 */
70- protected function __destruct () {
76+ public function __destruct () {
7177 $ this ->save (serialize ($ _SESSION ));
7278 $ this ->logger ->debug ("Saved session " );
7379 }
@@ -77,7 +83,7 @@ protected function __destruct() {
7783 * @return string a serialized string
7884 */
7985 public function load () {
80- $ this ->original = $ this ->getByKey ($ this ->getKeys ()) . '' ;
86+ $ this ->original = $ this ->repository -> getByKey ($ this ->getKeys ()) . '' ;
8187 $ this ->logger ->debug ("Loading session " );
8288 return $ this ->original ;
8389 }
@@ -88,12 +94,17 @@ public function load() {
8894 * @return boolean was it saved?
8995 */
9096 public function save ($ data ) {
97+ if ($ this ->wasStored ) {
98+ $ this ->logger ->debug ("Already saved, nothing to store " );
99+ return ;
100+ }
101+ $ this ->wasStored ;
91102 if ($ data === $ this ->original ) {
92103 $ this ->logger ->debug ("Session unchanged, nothing to store " );
93104 return true ; //nothing to change
94105 }
95106 $ this ->logger ->debug ("Session changed, storing " );
96- return $ this ->repository ->updateByKey ($ this ->getKeys (), $ data );
107+ return $ this ->repository ->setByKey ($ this ->getKeys (), $ data );
97108 }
98109
99110 /**
0 commit comments