@@ -234,6 +234,30 @@ static PHP_METHOD(Session, getOperationTime)
234234 php_phongo_new_timestamp_from_increment_and_timestamp (return_value , increment , timestamp TSRMLS_CC );
235235} /* }}} */
236236
237+ /* {{{ proto MongoDB\Driver\Server|null MongoDB\Driver\Session::getServer()
238+ Returns the server this session is pinned to */
239+ static PHP_METHOD (Session , getServer )
240+ {
241+ php_phongo_session_t * intern ;
242+ uint32_t server_id = 0 ;
243+
244+ intern = Z_SESSION_OBJ_P (getThis ());
245+ SESSION_CHECK_LIVELINESS (intern , "getServer" )
246+
247+ if (zend_parse_parameters_none () == FAILURE ) {
248+ return ;
249+ }
250+
251+ server_id = mongoc_client_session_get_server_id (intern -> client_session );
252+
253+ /* For sessions without a pinned server, 0 is returned. */
254+ if (!server_id ) {
255+ RETURN_NULL ();
256+ }
257+
258+ phongo_server_init (return_value , mongoc_client_session_get_client (intern -> client_session ), server_id TSRMLS_CC );
259+ } /* }}} */
260+
237261/* Creates a opts structure from an array optionally containing an RP, RC,
238262 * WC object, and/or maxCommitTimeMS int. Returns NULL if no options were found,
239263 * or there was an invalid option. If there was an invalid option or structure,
@@ -461,6 +485,7 @@ static zend_function_entry php_phongo_session_me[] = {
461485 PHP_ME (Session , getClusterTime , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
462486 PHP_ME (Session , getLogicalSessionId , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
463487 PHP_ME (Session , getOperationTime , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
488+ PHP_ME (Session , getServer , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
464489 PHP_ME (Session , isInTransaction , ai_Session_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
465490 PHP_ME (Session , startTransaction , ai_Session_startTransaction , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
466491 ZEND_NAMED_ME (__construct , PHP_FN (MongoDB_disabled___construct ), ai_Session_void , ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )
@@ -601,6 +626,30 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
601626 ADD_ASSOC_NULL_EX (& retval , "operationTime" );
602627 }
603628
629+ if (intern -> client_session ) {
630+ uint32_t server_id = mongoc_client_session_get_server_id (intern -> client_session );
631+
632+ if (server_id ) {
633+
634+ #if PHP_VERSION_ID >= 70000
635+ zval server ;
636+
637+ phongo_server_init (& server , mongoc_client_session_get_client (intern -> client_session ), server_id TSRMLS_CC );
638+ ADD_ASSOC_ZVAL_EX (& retval , "server" , & server );
639+ #else
640+ zval * server = NULL ;
641+
642+ MAKE_STD_ZVAL (server );
643+ phongo_server_init (server , mongoc_client_session_get_client (intern -> client_session ), server_id TSRMLS_CC );
644+ ADD_ASSOC_ZVAL_EX (& retval , "server" , server );
645+ #endif
646+ } else {
647+ ADD_ASSOC_NULL_EX (& retval , "server" );
648+ }
649+ } else {
650+ ADD_ASSOC_NULL_EX (& retval , "server" );
651+ }
652+
604653 return Z_ARRVAL (retval );
605654} /* }}} */
606655/* }}} */
0 commit comments