@@ -931,8 +931,6 @@ void php_phongo_read_concern_to_zval(zval *retval, const mongoc_read_concern_t *
931931
932932 if (level ) {
933933 ADD_ASSOC_STRING (retval , "level" , (char * )level );
934- } else {
935- ADD_ASSOC_NULL_EX (retval , "level" );
936934 }
937935} /* }}} */
938936
@@ -962,12 +960,21 @@ bool php_phongo_read_preference_tags_are_valid(const bson_t *tags) /* {{{ */
962960void php_phongo_read_preference_to_zval (zval * retval , const mongoc_read_prefs_t * read_prefs ) /* {{{ */
963961{
964962 const bson_t * tags = mongoc_read_prefs_get_tags (read_prefs );
963+ mongoc_read_mode_t mode = mongoc_read_prefs_get_mode (read_prefs );
965964
966965 array_init_size (retval , 2 );
967966
968- ADD_ASSOC_LONG_EX (retval , "mode" , mongoc_read_prefs_get_mode (read_prefs ));
967+ switch (mode ) {
968+ case MONGOC_READ_PRIMARY : ADD_ASSOC_STRING (retval , "mode" , "primary" ); break ;
969+ case MONGOC_READ_PRIMARY_PREFERRED : ADD_ASSOC_STRING (retval , "mode" , "primaryPreferred" ); break ;
970+ case MONGOC_READ_SECONDARY : ADD_ASSOC_STRING (retval , "mode" , "secondary" ); break ;
971+ case MONGOC_READ_SECONDARY_PREFERRED : ADD_ASSOC_STRING (retval , "mode" , "secondaryPreferred" ); break ;
972+ case MONGOC_READ_NEAREST : ADD_ASSOC_STRING (retval , "mode" , "nearest" ); break ;
973+ default : /* Do nothing */
974+ break ;
975+ }
969976
970- if (tags -> len ) {
977+ if (! bson_empty0 ( tags ) ) {
971978 php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER ;
972979 /* Use native arrays for debugging output */
973980 state .map .root_type = PHONGO_TYPEMAP_NATIVE_ARRAY ;
@@ -979,15 +986,14 @@ void php_phongo_read_preference_to_zval(zval *retval, const mongoc_read_prefs_t
979986#else
980987 ADD_ASSOC_ZVAL_EX (retval , "tags" , state .zchild );
981988#endif
982- } else {
983- ADD_ASSOC_NULL_EX (retval , "tags" );
984989 }
985990} /* }}} */
986991
987992void php_phongo_write_concern_to_zval (zval * retval , const mongoc_write_concern_t * write_concern ) /* {{{ */
988993{
989994 const char * wtag = mongoc_write_concern_get_wtag (write_concern );
990995 const int32_t w = mongoc_write_concern_get_w (write_concern );
996+ const int32_t wtimeout = mongoc_write_concern_get_wtimeout (write_concern );
991997
992998 array_init_size (retval , 4 );
993999
@@ -997,17 +1003,14 @@ void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t
9971003 ADD_ASSOC_STRING (retval , "w" , (char * )PHONGO_WRITE_CONCERN_W_MAJORITY );
9981004 } else if (w != MONGOC_WRITE_CONCERN_W_DEFAULT ) {
9991005 ADD_ASSOC_LONG_EX (retval , "w" , w );
1000- } else {
1001- ADD_ASSOC_NULL_EX (retval , "w" );
10021006 }
10031007
1004- ADD_ASSOC_BOOL_EX (retval , "wmajority" , mongoc_write_concern_get_wmajority (write_concern ));
1005- ADD_ASSOC_LONG_EX (retval , "wtimeout" , mongoc_write_concern_get_wtimeout (write_concern ));
1006-
10071008 if (mongoc_write_concern_journal_is_set (write_concern )) {
1008- ADD_ASSOC_BOOL_EX (retval , "journal" , mongoc_write_concern_get_journal (write_concern ));
1009- } else {
1010- ADD_ASSOC_NULL_EX (retval , "journal" );
1009+ ADD_ASSOC_BOOL_EX (retval , "j" , mongoc_write_concern_get_journal (write_concern ));
1010+ }
1011+
1012+ if (wtimeout != 0 ) {
1013+ ADD_ASSOC_LONG_EX (retval , "wtimeout" , wtimeout );
10111014 }
10121015} /* }}} */
10131016/* }}} */
@@ -2105,6 +2108,20 @@ PHP_MINIT_FUNCTION(mongodb)
21052108
21062109 PHP_MINIT (bson )(INIT_FUNC_ARGS_PASSTHRU );
21072110
2111+ PHP_MINIT (Type )(INIT_FUNC_ARGS_PASSTHRU );
2112+ PHP_MINIT (Serializable )(INIT_FUNC_ARGS_PASSTHRU );
2113+ PHP_MINIT (Unserializable )(INIT_FUNC_ARGS_PASSTHRU );
2114+ PHP_MINIT (Persistable )(INIT_FUNC_ARGS_PASSTHRU );
2115+ PHP_MINIT (Binary )(INIT_FUNC_ARGS_PASSTHRU );
2116+ PHP_MINIT (Decimal128 )(INIT_FUNC_ARGS_PASSTHRU );
2117+ PHP_MINIT (Javascript )(INIT_FUNC_ARGS_PASSTHRU );
2118+ PHP_MINIT (MaxKey )(INIT_FUNC_ARGS_PASSTHRU );
2119+ PHP_MINIT (MinKey )(INIT_FUNC_ARGS_PASSTHRU );
2120+ PHP_MINIT (ObjectID )(INIT_FUNC_ARGS_PASSTHRU );
2121+ PHP_MINIT (Regex )(INIT_FUNC_ARGS_PASSTHRU );
2122+ PHP_MINIT (Timestamp )(INIT_FUNC_ARGS_PASSTHRU );
2123+ PHP_MINIT (UTCDateTime )(INIT_FUNC_ARGS_PASSTHRU );
2124+
21082125 PHP_MINIT (Command )(INIT_FUNC_ARGS_PASSTHRU );
21092126 PHP_MINIT (Cursor )(INIT_FUNC_ARGS_PASSTHRU );
21102127 PHP_MINIT (CursorId )(INIT_FUNC_ARGS_PASSTHRU );
@@ -2132,20 +2149,6 @@ PHP_MINIT_FUNCTION(mongodb)
21322149 PHP_MINIT (ExecutionTimeoutException )(INIT_FUNC_ARGS_PASSTHRU );
21332150 PHP_MINIT (ConnectionTimeoutException )(INIT_FUNC_ARGS_PASSTHRU );
21342151
2135- PHP_MINIT (Type )(INIT_FUNC_ARGS_PASSTHRU );
2136- PHP_MINIT (Serializable )(INIT_FUNC_ARGS_PASSTHRU );
2137- PHP_MINIT (Unserializable )(INIT_FUNC_ARGS_PASSTHRU );
2138- PHP_MINIT (Persistable )(INIT_FUNC_ARGS_PASSTHRU );
2139- PHP_MINIT (Binary )(INIT_FUNC_ARGS_PASSTHRU );
2140- PHP_MINIT (Decimal128 )(INIT_FUNC_ARGS_PASSTHRU );
2141- PHP_MINIT (Javascript )(INIT_FUNC_ARGS_PASSTHRU );
2142- PHP_MINIT (MaxKey )(INIT_FUNC_ARGS_PASSTHRU );
2143- PHP_MINIT (MinKey )(INIT_FUNC_ARGS_PASSTHRU );
2144- PHP_MINIT (ObjectID )(INIT_FUNC_ARGS_PASSTHRU );
2145- PHP_MINIT (Regex )(INIT_FUNC_ARGS_PASSTHRU );
2146- PHP_MINIT (Timestamp )(INIT_FUNC_ARGS_PASSTHRU );
2147- PHP_MINIT (UTCDateTime )(INIT_FUNC_ARGS_PASSTHRU );
2148-
21492152 REGISTER_STRING_CONSTANT ("MONGODB_VERSION" , (char * )MONGODB_VERSION_S , CONST_CS | CONST_PERSISTENT );
21502153 REGISTER_STRING_CONSTANT ("MONGODB_STABILITY" , (char * )MONGODB_STABILITY_S , CONST_CS | CONST_PERSISTENT );
21512154
0 commit comments