@@ -16,7 +16,15 @@ class SessionHandler implements \SessionHandlerInterface
1616 private $ client ;
1717
1818 /**
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+ * }
2028 */
2129 private $ options ;
2230
@@ -54,11 +62,11 @@ class SessionHandler implements \SessionHandlerInterface
5462 public function __construct (DynamoDbClient $ client , array $ options )
5563 {
5664 $ 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 ' ] ?? '_ ' ;
5769 $ 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 ' ] ?? '_ ' ;
6270 }
6371
6472 public function setUp (): void
@@ -104,7 +112,7 @@ public function close()
104112 $ id = session_id ();
105113
106114 // 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 ) ) {
108116 $ this ->sessionWritten = $ this ->doWrite ($ id , false );
109117 }
110118
@@ -223,6 +231,9 @@ private function formatId(string $id): string
223231 return trim ($ this ->sessionName . $ this ->options ['id_separator ' ] . $ id , $ this ->options ['id_separator ' ]);
224232 }
225233
234+ /**
235+ * @return array<string, array{S: string}>
236+ */
226237 private function formatKey (string $ key ): array
227238 {
228239 return [$ this ->options ['hash_key ' ] => ['S ' => $ key ]];
0 commit comments