33
44namespace Spaze \Session ;
55
6- use Nette \Database \Context ;
6+ use Nette \Database \Explorer ;
77use Nette \Database \Table \ActiveRow ;
88use Nette \SmartObject ;
99use SessionHandlerInterface ;
@@ -19,7 +19,7 @@ class MysqlSessionHandler implements SessionHandlerInterface
1919 use SmartObject;
2020
2121
22- private Context $ context ;
22+ private Explorer $ explorer ;
2323
2424 private ?StaticKeyEncryption $ encryptionService = null ;
2525
@@ -51,9 +51,9 @@ class MysqlSessionHandler implements SessionHandlerInterface
5151 public $ onBeforeDataWrite ;
5252
5353
54- public function __construct (Context $ context )
54+ public function __construct (Explorer $ explorer )
5555 {
56- $ this ->context = $ context ;
56+ $ this ->explorer = $ explorer ;
5757 }
5858
5959
@@ -106,7 +106,7 @@ private function lock(): void
106106 $ sessionId = \session_id ();
107107 if ($ sessionId ) {
108108 $ this ->lockId = $ this ->hash ($ sessionId , false );
109- $ this ->context ->query ('SELECT GET_LOCK(?, ?) as `lock` ' , $ this ->lockId , $ this ->lockTimeout );
109+ $ this ->explorer ->query ('SELECT GET_LOCK(?, ?) as `lock` ' , $ this ->lockId , $ this ->lockTimeout );
110110 }
111111 }
112112 }
@@ -118,7 +118,7 @@ private function unlock(): void
118118 return ;
119119 }
120120
121- $ this ->context ->query ('SELECT RELEASE_LOCK(?) ' , $ this ->lockId );
121+ $ this ->explorer ->query ('SELECT RELEASE_LOCK(?) ' , $ this ->lockId );
122122 $ this ->lockId = null ;
123123 }
124124
@@ -149,7 +149,7 @@ public function close(): bool
149149 public function destroy ($ sessionId ): bool
150150 {
151151 $ hashedSessionId = $ this ->hash ($ sessionId );
152- $ this ->context ->table ($ this ->tableName )->where ('id ' , $ hashedSessionId )->delete ();
152+ $ this ->explorer ->table ($ this ->tableName )->where ('id ' , $ hashedSessionId )->delete ();
153153 $ this ->unlock ();
154154 return true ;
155155 }
@@ -163,7 +163,7 @@ public function read($sessionId): string
163163 {
164164 $ this ->lock ();
165165 $ hashedSessionId = $ this ->hash ($ sessionId );
166- $ this ->row = $ this ->context ->table ($ this ->tableName )->get ($ hashedSessionId );
166+ $ this ->row = $ this ->explorer ->table ($ this ->tableName )->get ($ hashedSessionId );
167167
168168 if ($ this ->row ) {
169169 $ this ->data [$ sessionId ] = ($ this ->encryptionService ? $ this ->encryptionService ->decrypt ($ this ->row ->data ) : $ this ->row ->data );
@@ -189,14 +189,14 @@ public function write($sessionId, $sessionData): bool
189189 $ sessionData = $ this ->encryptionService ->encrypt ($ sessionData );
190190 }
191191 $ this ->onBeforeDataWrite ();
192- $ row = $ this ->context ->table ($ this ->tableName )->get ($ hashedSessionId );
192+ $ row = $ this ->explorer ->table ($ this ->tableName )->get ($ hashedSessionId );
193193 if ($ row ) {
194194 $ row ->update ([
195195 'timestamp ' => $ time ,
196196 'data ' => $ sessionData ,
197197 ] + $ this ->additionalData );
198198 } else {
199- $ this ->context ->table ($ this ->tableName )->insert ([
199+ $ this ->explorer ->table ($ this ->tableName )->insert ([
200200 'id ' => $ hashedSessionId ,
201201 'timestamp ' => $ time ,
202202 'data ' => $ sessionData ,
@@ -230,12 +230,12 @@ public function gc($maxLifeTime): bool
230230 // In a typical master-master replication setup, the server IDs are 1 and 2.
231231 // There is no subtraction on server 1 and one day (or one tenth of $maxLifeTime)
232232 // subtraction on server 2.
233- $ row = $ this ->context ->query ('SELECT @@server_id as `serverId` ' )->fetch ();
233+ $ row = $ this ->explorer ->query ('SELECT @@server_id as `serverId` ' )->fetch ();
234234 if ($ row && $ row ->serverId > 1 && $ row ->serverId < 10 ) {
235235 $ maxTimestamp -= ($ row ->serverId - 1 ) * \max (86400 , $ maxLifeTime / 10 );
236236 }
237237
238- $ this ->context ->table ($ this ->tableName )
238+ $ this ->explorer ->table ($ this ->tableName )
239239 ->where ('timestamp < ? ' , $ maxTimestamp )
240240 ->delete ();
241241
0 commit comments