@@ -98,6 +98,51 @@ static const char* php_phongo_get_transaction_state_string(mongoc_transaction_st
9898 }
9999}
100100
101+ static void php_phongo_transaction_options_to_zval (mongoc_transaction_opt_t * opts , zval * retval )
102+ {
103+ int64_t max_commit_time_ms ;
104+ const mongoc_read_concern_t * read_concern ;
105+ const mongoc_read_prefs_t * read_preference ;
106+ const mongoc_write_concern_t * write_concern ;
107+
108+ if (!opts ) {
109+ ZVAL_NULL (retval );
110+ return ;
111+ }
112+
113+ max_commit_time_ms = mongoc_transaction_opts_get_max_commit_time_ms (opts );
114+ read_concern = mongoc_transaction_opts_get_read_concern (opts );
115+ read_preference = mongoc_transaction_opts_get_read_prefs (opts );
116+ write_concern = mongoc_transaction_opts_get_write_concern (opts );
117+
118+ array_init_size (retval , 4 );
119+
120+ if (max_commit_time_ms ) {
121+ ADD_ASSOC_LONG_EX (retval , "maxCommitTimeMS" , max_commit_time_ms );
122+ }
123+
124+ if (!mongoc_read_concern_is_default (read_concern )) {
125+ zval zread_concern ;
126+
127+ phongo_readconcern_init (& zread_concern , read_concern );
128+ ADD_ASSOC_ZVAL_EX (retval , "readConcern" , & zread_concern );
129+ }
130+
131+ if (read_preference ) {
132+ zval zread_preference ;
133+
134+ phongo_readpreference_init (& zread_preference , read_preference );
135+ ADD_ASSOC_ZVAL_EX (retval , "readPreference" , & zread_preference );
136+ }
137+
138+ if (!mongoc_write_concern_is_default (write_concern )) {
139+ zval zwrite_concern ;
140+
141+ phongo_writeconcern_init (& zwrite_concern , write_concern );
142+ ADD_ASSOC_ZVAL_EX (retval , "writeConcern" , & zwrite_concern );
143+ }
144+ }
145+
101146/* {{{ proto void MongoDB\Driver\Session::advanceClusterTime(array|object $clusterTime)
102147 Advances the cluster time for this Session */
103148static PHP_METHOD (Session , advanceClusterTime )
@@ -287,13 +332,8 @@ static PHP_METHOD(Session, getServer)
287332 Returns options for the currently running transaction */
288333static PHP_METHOD (Session , getTransactionOptions )
289334{
290- zend_error_handling error_handling ;
291- php_phongo_session_t * intern ;
292- mongoc_transaction_opt_t * opts ;
293- int64_t max_commit_time_ms ;
294- const mongoc_read_concern_t * read_concern ;
295- const mongoc_read_prefs_t * read_preference ;
296- const mongoc_write_concern_t * write_concern ;
335+ zend_error_handling error_handling ;
336+ php_phongo_session_t * intern ;
297337
298338 intern = Z_SESSION_OBJ_P (getThis ());
299339 SESSION_CHECK_LIVELINESS (intern , "getTransactionOptions" )
@@ -305,43 +345,7 @@ static PHP_METHOD(Session, getTransactionOptions)
305345 }
306346 zend_restore_error_handling (& error_handling );
307347
308- opts = mongoc_session_opts_get_transaction_opts (intern -> client_session );
309-
310- if (!opts ) {
311- return ;
312- }
313-
314- max_commit_time_ms = mongoc_transaction_opts_get_max_commit_time_ms (opts );
315- read_concern = mongoc_transaction_opts_get_read_concern (opts );
316- read_preference = mongoc_transaction_opts_get_read_prefs (opts );
317- write_concern = mongoc_transaction_opts_get_write_concern (opts );
318-
319- array_init_size (return_value , 4 );
320-
321- if (max_commit_time_ms ) {
322- ADD_ASSOC_LONG_EX (return_value , "maxCommitTimeMS" , max_commit_time_ms );
323- }
324-
325- if (!mongoc_read_concern_is_default (read_concern )) {
326- zval zread_concern ;
327-
328- phongo_readconcern_init (& zread_concern , read_concern );
329- ADD_ASSOC_ZVAL_EX (return_value , "readConcern" , & zread_concern );
330- }
331-
332- if (read_preference ) {
333- zval zread_preference ;
334-
335- phongo_readpreference_init (& zread_preference , read_preference );
336- ADD_ASSOC_ZVAL_EX (return_value , "readPreference" , & zread_preference );
337- }
338-
339- if (!mongoc_write_concern_is_default (write_concern )) {
340- zval zwrite_concern ;
341-
342- phongo_writeconcern_init (& zwrite_concern , write_concern );
343- ADD_ASSOC_ZVAL_EX (return_value , "writeConcern" , & zwrite_concern );
344- }
348+ php_phongo_transaction_options_to_zval (mongoc_session_opts_get_transaction_opts (intern -> client_session ), return_value );
345349} /* }}} */
346350
347351/* {{{ proto string MongoDB\Driver\Session::getTransactionState()
@@ -674,9 +678,8 @@ static zend_object* php_phongo_session_create_object(zend_class_entry* class_typ
674678
675679static HashTable * php_phongo_session_get_debug_info (phongo_compat_object_handler_type * object , int * is_temp ) /* {{{ */
676680{
677- php_phongo_session_t * intern = NULL ;
678- const mongoc_session_opt_t * cs_opts ;
679- zval retval = ZVAL_STATIC_INIT ;
681+ php_phongo_session_t * intern = NULL ;
682+ zval retval = ZVAL_STATIC_INIT ;
680683
681684 * is_temp = 1 ;
682685 intern = Z_OBJ_SESSION (PHONGO_COMPAT_GET_OBJ (object ));
@@ -725,6 +728,7 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler
725728 }
726729
727730 if (intern -> client_session ) {
731+ const mongoc_session_opt_t * cs_opts ;
728732 cs_opts = mongoc_client_session_get_opts (intern -> client_session );
729733 ADD_ASSOC_BOOL_EX (& retval , "causalConsistency" , mongoc_session_opts_get_causal_consistency (cs_opts ));
730734 } else {
@@ -764,6 +768,41 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler
764768 ADD_ASSOC_NULL_EX (& retval , "server" );
765769 }
766770
771+ if (intern -> client_session ) {
772+ ADD_ASSOC_BOOL_EX (& retval , "inTransaction" , mongoc_client_session_in_transaction (intern -> client_session ));
773+ } else {
774+ ADD_ASSOC_NULL_EX (& retval , "inTransaction" );
775+ }
776+
777+ if (intern -> client_session ) {
778+ const char * state = php_phongo_get_transaction_state_string (mongoc_client_session_get_transaction_state (intern -> client_session ));
779+
780+ if (!state ) {
781+ /* Exception should already have been thrown */
782+ goto done ;
783+ }
784+
785+ ADD_ASSOC_STRING (& retval , "transactionState" , state );
786+ } else {
787+ ADD_ASSOC_NULL_EX (& retval , "transactionState" );
788+ }
789+
790+ if (intern -> client_session ) {
791+ mongoc_transaction_opt_t * txn_opts = mongoc_session_opts_get_transaction_opts (intern -> client_session );
792+
793+ if (txn_opts ) {
794+
795+ zval transaction ;
796+
797+ php_phongo_transaction_options_to_zval (txn_opts , & transaction );
798+ ADD_ASSOC_ZVAL_EX (& retval , "transactionOptions" , & transaction );
799+ } else {
800+ ADD_ASSOC_NULL_EX (& retval , "transactionOptions" );
801+ }
802+ } else {
803+ ADD_ASSOC_NULL_EX (& retval , "transactionOptions" );
804+ }
805+
767806done :
768807 return Z_ARRVAL (retval );
769808} /* }}} */
0 commit comments