@@ -262,6 +262,87 @@ static PHP_METHOD(Session, getServer)
262
262
phongo_server_init (return_value , mongoc_client_session_get_client (intern -> client_session ), server_id TSRMLS_CC );
263
263
} /* }}} */
264
264
265
+ /* {{{ proto array|null MongoDB\Driver\Session::getTransactionOptions()
266
+ Returns options for the currently running transaction */
267
+ static PHP_METHOD (Session , getTransactionOptions )
268
+ {
269
+ php_phongo_session_t * intern ;
270
+ mongoc_transaction_opt_t * opts ;
271
+ int64_t max_commit_time_ms ;
272
+ const mongoc_read_concern_t * read_concern ;
273
+ const mongoc_read_prefs_t * read_preference ;
274
+ const mongoc_write_concern_t * write_concern ;
275
+
276
+ intern = Z_SESSION_OBJ_P (getThis ());
277
+ SESSION_CHECK_LIVELINESS (intern , "getTransactionOptions" )
278
+
279
+ if (zend_parse_parameters_none () == FAILURE ) {
280
+ return ;
281
+ }
282
+
283
+ opts = mongoc_session_opts_get_transaction_opts (intern -> client_session );
284
+
285
+ if (!opts ) {
286
+ return ;
287
+ }
288
+
289
+ max_commit_time_ms = mongoc_transaction_opts_get_max_commit_time_ms (opts );
290
+ read_concern = mongoc_transaction_opts_get_read_concern (opts );
291
+ read_preference = mongoc_transaction_opts_get_read_prefs (opts );
292
+ write_concern = mongoc_transaction_opts_get_write_concern (opts );
293
+
294
+ array_init_size (return_value , 4 );
295
+
296
+ if (max_commit_time_ms ) {
297
+ ADD_ASSOC_LONG_EX (return_value , "maxCommitTimeMS" , max_commit_time_ms );
298
+ }
299
+
300
+ if (!mongoc_read_concern_is_default (read_concern )) {
301
+ #if PHP_VERSION_ID >= 70000
302
+ zval zread_concern ;
303
+
304
+ phongo_readconcern_init (& zread_concern , read_concern TSRMLS_CC );
305
+ ADD_ASSOC_ZVAL_EX (return_value , "readConcern" , & zread_concern );
306
+ #else
307
+ zval * zread_concern = NULL ;
308
+ MAKE_STD_ZVAL (zread_concern );
309
+
310
+ phongo_readconcern_init (zread_concern , read_concern TSRMLS_CC );
311
+ ADD_ASSOC_ZVAL_EX (return_value , "readConcern" , zread_concern );
312
+ #endif
313
+ }
314
+
315
+ if (read_preference ) {
316
+ #if PHP_VERSION_ID >= 70000
317
+ zval zread_preference ;
318
+
319
+ phongo_readpreference_init (& zread_preference , read_preference TSRMLS_CC );
320
+ ADD_ASSOC_ZVAL_EX (return_value , "readPreference" , & zread_preference );
321
+ #else
322
+ zval * zread_preference = NULL ;
323
+ MAKE_STD_ZVAL (zread_preference );
324
+
325
+ phongo_readpreference_init (zread_preference , read_preference TSRMLS_CC );
326
+ ADD_ASSOC_ZVAL_EX (return_value , "readPreference" , zread_preference );
327
+ #endif
328
+ }
329
+
330
+ if (!mongoc_write_concern_is_default (write_concern )) {
331
+ #if PHP_VERSION_ID >= 70000
332
+ zval zwrite_concern ;
333
+
334
+ phongo_writeconcern_init (& zwrite_concern , write_concern TSRMLS_CC );
335
+ ADD_ASSOC_ZVAL_EX (return_value , "writeConcern" , & zwrite_concern );
336
+ #else
337
+ zval * zwrite_concern = NULL ;
338
+ MAKE_STD_ZVAL (zwrite_concern );
339
+
340
+ phongo_writeconcern_init (zwrite_concern , write_concern TSRMLS_CC );
341
+ ADD_ASSOC_ZVAL_EX (return_value , "writeConcern" , zwrite_concern );
342
+ #endif
343
+ }
344
+ } /* }}} */
345
+
265
346
/* Creates a opts structure from an array optionally containing an RP, RC,
266
347
* WC object, and/or maxCommitTimeMS int. Returns NULL if no options were found,
267
348
* or there was an invalid option. If there was an invalid option or structure,
@@ -490,6 +571,7 @@ static zend_function_entry php_phongo_session_me[] = {
490
571
PHP_ME (Session , getLogicalSessionId , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
491
572
PHP_ME (Session , getOperationTime , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
492
573
PHP_ME (Session , getServer , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
574
+ PHP_ME (Session , getTransactionOptions , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
493
575
PHP_ME (Session , isInTransaction , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
494
576
PHP_ME (Session , startTransaction , ai_Session_startTransaction , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
495
577
ZEND_NAMED_ME (__construct , PHP_FN (MongoDB_disabled___construct ), ai_Session_void , ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )
0 commit comments