2020 * @author Ross Motley <ross.motley@amara.com>
2121 * @author Oliver Radwell <oliver.radwell@amara.com>
2222 */
23- class MigratingSessionHandler implements \SessionHandlerInterface
23+ class MigratingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
2424{
2525 private $ currentHandler ;
2626 private $ writeOnlyHandler ;
2727
2828 public function __construct (\SessionHandlerInterface $ currentHandler , \SessionHandlerInterface $ writeOnlyHandler )
2929 {
30+ if (!$ currentHandler instanceof \SessionUpdateTimestampHandlerInterface) {
31+ $ currentHandler = new StrictSessionHandler ($ currentHandler );
32+ }
33+ if (!$ writeOnlyHandler instanceof \SessionUpdateTimestampHandlerInterface) {
34+ $ writeOnlyHandler = new StrictSessionHandler ($ writeOnlyHandler );
35+ }
36+
3037 $ this ->currentHandler = $ currentHandler ;
3138 $ this ->writeOnlyHandler = $ writeOnlyHandler ;
3239 }
@@ -67,10 +74,10 @@ public function gc($maxlifetime)
6774 /**
6875 * {@inheritdoc}
6976 */
70- public function open ($ savePath , $ sessionId )
77+ public function open ($ savePath , $ sessionName )
7178 {
72- $ result = $ this ->currentHandler ->open ($ savePath , $ sessionId );
73- $ this ->writeOnlyHandler ->open ($ savePath , $ sessionId );
79+ $ result = $ this ->currentHandler ->open ($ savePath , $ sessionName );
80+ $ this ->writeOnlyHandler ->open ($ savePath , $ sessionName );
7481
7582 return $ result ;
7683 }
@@ -94,4 +101,24 @@ public function write($sessionId, $sessionData)
94101
95102 return $ result ;
96103 }
104+
105+ /**
106+ * {@inheritdoc}
107+ */
108+ public function validateId ($ sessionId )
109+ {
110+ // No reading from new handler until switch-over
111+ return $ this ->currentHandler ->validateId ($ sessionId );
112+ }
113+
114+ /**
115+ * {@inheritdoc}
116+ */
117+ public function updateTimestamp ($ sessionId , $ sessionData )
118+ {
119+ $ result = $ this ->currentHandler ->updateTimestamp ($ sessionId , $ sessionData );
120+ $ this ->writeOnlyHandler ->updateTimestamp ($ sessionId , $ sessionData );
121+
122+ return $ result ;
123+ }
97124}
0 commit comments