38
38
use Psr \Http \Message \UriInterface ;
39
39
use Psr \Log \LogLevel ;
40
40
use Throwable ;
41
+ use Traversable ;
41
42
use WeakReference ;
42
43
43
44
/**
@@ -209,12 +210,14 @@ public function reset(): void
209
210
* Begins a transaction.
210
211
*
211
212
* Any of the preconditioned states are: 'READY', 'INTERRUPTED'.
213
+ *
214
+ * @param iterable<string, scalar|array|null>|null $txMetaData
212
215
*/
213
- public function begin (?string $ database , ?float $ timeout , BookmarkHolder $ holder ): void
216
+ public function begin (?string $ database , ?float $ timeout , BookmarkHolder $ holder, ? iterable $ txMetaData ): void
214
217
{
215
218
$ this ->consumeResults ();
216
219
217
- $ extra = $ this ->buildRunExtra ($ database , $ timeout , $ holder , AccessMode::WRITE ());
220
+ $ extra = $ this ->buildRunExtra ($ database , $ timeout , $ holder , AccessMode::WRITE (), $ txMetaData );
218
221
$ message = $ this ->messageFactory ->createBeginMessage ($ extra );
219
222
$ response = $ message ->send ()->getResponse ();
220
223
$ this ->assertNoFailure ($ response );
@@ -248,8 +251,9 @@ public function run(
248
251
?float $ timeout ,
249
252
BookmarkHolder $ holder ,
250
253
?AccessMode $ mode ,
254
+ ?iterable $ tsxMetadata ,
251
255
): array {
252
- $ extra = $ this ->buildRunExtra ($ database , $ timeout , $ holder , $ mode );
256
+ $ extra = $ this ->buildRunExtra ($ database , $ timeout , $ holder , $ mode, $ tsxMetadata );
253
257
$ message = $ this ->messageFactory ->createRunMessage ($ text , $ parameters , $ extra );
254
258
$ response = $ message ->send ()->getResponse ();
255
259
$ this ->assertNoFailure ($ response );
@@ -327,7 +331,7 @@ public function close(): void
327
331
}
328
332
}
329
333
330
- private function buildRunExtra (?string $ database , ?float $ timeout , BookmarkHolder $ holder , ?AccessMode $ mode ): array
334
+ private function buildRunExtra (?string $ database , ?float $ timeout , BookmarkHolder $ holder , ?AccessMode $ mode, ? iterable $ metadata ): array
331
335
{
332
336
$ extra = [];
333
337
if ($ database !== null ) {
@@ -345,6 +349,13 @@ private function buildRunExtra(?string $database, ?float $timeout, BookmarkHolde
345
349
$ extra ['mode ' ] = AccessMode::WRITE () === $ mode ? 'w ' : 'r ' ;
346
350
}
347
351
352
+ if ($ metadata !== null ) {
353
+ $ metadataArray = $ metadata instanceof Traversable ? iterator_to_array ($ metadata ) : $ metadata ;
354
+ if (count ($ metadataArray ) > 0 ) {
355
+ $ extra ['tx_metadata ' ] = $ metadataArray ;
356
+ }
357
+ }
358
+
348
359
return $ extra ;
349
360
}
350
361
0 commit comments