2
2
3
3
namespace YetAnotherWebStack \PhpMemcachedSession \Model ;
4
4
5
- class Session implements YetAnotherWebStack \PhpMemcachedSession \Interfaces \Model {
5
+ class Session implements \ YetAnotherWebStack \PhpMemcachedSession \Interfaces \Model {
6
6
7
7
/**
8
8
*
@@ -40,12 +40,18 @@ class Session implements YetAnotherWebStack\PhpMemcachedSession\Interfaces\Model
40
40
*/
41
41
protected $ logger ;
42
42
43
+ /**
44
+ *
45
+ * @var boolean
46
+ */
47
+ protected $ wasStored = false ;
48
+
43
49
/**
44
50
*
45
51
* @param string $sessionId
46
52
* @param \YetAnotherWebStack\PhpMemcachedSession\Interfaces\Repository $repository
47
53
*/
48
- protected function __construct ($ sessionId ,
54
+ public function __construct ($ sessionId ,
49
55
\YetAnotherWebStack \PhpMemcachedSession \Interfaces \Repository $ repository ,
50
56
\Psr \Log \LoggerInterface $ logger ) {
51
57
$ this ->logger = $ logger ;
@@ -67,7 +73,7 @@ protected function getKeys() {
67
73
/**
68
74
* stores the sessionId
69
75
*/
70
- protected function __destruct () {
76
+ public function __destruct () {
71
77
$ this ->save (serialize ($ _SESSION ));
72
78
$ this ->logger ->debug ("Saved session " );
73
79
}
@@ -77,7 +83,7 @@ protected function __destruct() {
77
83
* @return string a serialized string
78
84
*/
79
85
public function load () {
80
- $ this ->original = $ this ->getByKey ($ this ->getKeys ()) . '' ;
86
+ $ this ->original = $ this ->repository -> getByKey ($ this ->getKeys ()) . '' ;
81
87
$ this ->logger ->debug ("Loading session " );
82
88
return $ this ->original ;
83
89
}
@@ -88,12 +94,17 @@ public function load() {
88
94
* @return boolean was it saved?
89
95
*/
90
96
public function save ($ data ) {
97
+ if ($ this ->wasStored ) {
98
+ $ this ->logger ->debug ("Already saved, nothing to store " );
99
+ return ;
100
+ }
101
+ $ this ->wasStored ;
91
102
if ($ data === $ this ->original ) {
92
103
$ this ->logger ->debug ("Session unchanged, nothing to store " );
93
104
return true ; //nothing to change
94
105
}
95
106
$ this ->logger ->debug ("Session changed, storing " );
96
- return $ this ->repository ->updateByKey ($ this ->getKeys (), $ data );
107
+ return $ this ->repository ->setByKey ($ this ->getKeys (), $ data );
97
108
}
98
109
99
110
/**
0 commit comments