@@ -16,7 +16,15 @@ class SessionHandler implements \SessionHandlerInterface
16
16
private $ client ;
17
17
18
18
/**
19
- * @var array
19
+ * @var array{
20
+ * consistent_read?: bool,
21
+ * data_attribute: string,
22
+ * hash_key: string,
23
+ * session_lifetime?: int,
24
+ * session_lifetime_attribute: string,
25
+ * table_name: string,
26
+ * id_separator: string
27
+ * }
20
28
*/
21
29
private $ options ;
22
30
@@ -54,11 +62,11 @@ class SessionHandler implements \SessionHandlerInterface
54
62
public function __construct (DynamoDbClient $ client , array $ options )
55
63
{
56
64
$ this ->client = $ client ;
65
+ $ options ['data_attribute ' ] = $ options ['data_attribute ' ] ?? 'data ' ;
66
+ $ options ['hash_key ' ] = $ options ['hash_key ' ] ?? 'id ' ;
67
+ $ options ['session_lifetime_attribute ' ] = $ options ['session_lifetime_attribute ' ] ?? 'expires ' ;
68
+ $ options ['id_separator ' ] = $ options ['id_separator ' ] ?? '_ ' ;
57
69
$ this ->options = $ options ;
58
- $ this ->options ['data_attribute ' ] = $ this ->options ['data_attribute ' ] ?? 'data ' ;
59
- $ this ->options ['hash_key ' ] = $ this ->options ['hash_key ' ] ?? 'id ' ;
60
- $ this ->options ['session_lifetime_attribute ' ] = $ this ->options ['session_lifetime_attribute ' ] ?? 'expires ' ;
61
- $ this ->options ['id_separator ' ] = $ this ->options ['id_separator ' ] ?? '_ ' ;
62
70
}
63
71
64
72
public function setUp (): void
@@ -104,7 +112,7 @@ public function close()
104
112
$ id = session_id ();
105
113
106
114
// Make sure the expiration time is updated, even if the write did not occur
107
- if ($ this ->sessionId !== $ id || !$ this ->sessionWritten ) {
115
+ if (false !== $ id && ( $ this ->sessionId !== $ id || !$ this ->sessionWritten ) ) {
108
116
$ this ->sessionWritten = $ this ->doWrite ($ id , false );
109
117
}
110
118
@@ -223,6 +231,9 @@ private function formatId(string $id): string
223
231
return trim ($ this ->sessionName . $ this ->options ['id_separator ' ] . $ id , $ this ->options ['id_separator ' ]);
224
232
}
225
233
234
+ /**
235
+ * @return array<string, array{S: string}>
236
+ */
226
237
private function formatKey (string $ key ): array
227
238
{
228
239
return [$ this ->options ['hash_key ' ] => ['S ' => $ key ]];
0 commit comments