@@ -1111,23 +1111,29 @@ static bool php_phongo_apply_rp_options_to_uri(mongoc_uri_t *uri, bson_t *option
11111111 mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_SECONDARY_PREFERRED );
11121112 }
11131113
1114- if (bson_iter_init_find_case (& iter , options , MONGOC_URI_READPREFERENCE ) && BSON_ITER_HOLDS_UTF8 (& iter )) {
1115- const char * str = bson_iter_utf8 (& iter , NULL );
1114+ if (bson_iter_init_find_case (& iter , options , MONGOC_URI_READPREFERENCE )) {
1115+ const char * key = bson_iter_key (& iter );
1116+ if (BSON_ITER_HOLDS_UTF8 (& iter )) {
1117+ const char * str = bson_iter_utf8 (& iter , NULL );
11161118
1117- if (0 == strcasecmp ("primary" , str )) {
1118- mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_PRIMARY );
1119- } else if (0 == strcasecmp ("primarypreferred" , str )) {
1120- mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_PRIMARY_PREFERRED );
1121- } else if (0 == strcasecmp ("secondary" , str )) {
1122- mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_SECONDARY );
1123- } else if (0 == strcasecmp ("secondarypreferred" , str )) {
1124- mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_SECONDARY_PREFERRED );
1125- } else if (0 == strcasecmp ("nearest" , str )) {
1126- mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_NEAREST );
1127- } else {
1128- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Unsupported readPreference value: '%s'" , str );
1129- mongoc_read_prefs_destroy (new_rp );
1119+ if (0 == strcasecmp ("primary" , str )) {
1120+ mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_PRIMARY );
1121+ } else if (0 == strcasecmp ("primarypreferred" , str )) {
1122+ mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_PRIMARY_PREFERRED );
1123+ } else if (0 == strcasecmp ("secondary" , str )) {
1124+ mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_SECONDARY );
1125+ } else if (0 == strcasecmp ("secondarypreferred" , str )) {
1126+ mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_SECONDARY_PREFERRED );
1127+ } else if (0 == strcasecmp ("nearest" , str )) {
1128+ mongoc_read_prefs_set_mode (new_rp , MONGOC_READ_NEAREST );
1129+ } else {
1130+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Unsupported %s value: '%s'" , key , str );
1131+ mongoc_read_prefs_destroy (new_rp );
11301132
1133+ return false;
1134+ }
1135+ } else {
1136+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s URI option expected to be string" , key );
11311137 return false;
11321138 }
11331139 }
0 commit comments