Skip to content

Commit 12ec628

Browse files
committed
PHPC-609: Apply RC/RP/WC to mongoc_uri_t instead of mongoc_client_t
This refactors existing code to take advantage of new functions in mongoc_uri_t's public API.
1 parent 0bd38aa commit 12ec628

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

php_phongo.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "mongoc-bulk-operation-private.h"
3232
#include "mongoc-read-concern-private.h"
3333
#include "mongoc-write-concern-private.h"
34-
#include "mongoc-uri-private.h"
3534
#include "mongoc-trace.h"
3635

3736

@@ -1637,14 +1636,14 @@ void php_phongo_populate_default_ssl_ctx(php_stream_context *ctx, zval *driverOp
16371636
#undef SET_STRING_CTX
16381637
} /* }}} */
16391638

1640-
static bool php_phongo_apply_rc_options_to_client(mongoc_client_t *client, bson_t *options TSRMLS_DC) /* {{{ */
1639+
static bool php_phongo_apply_rc_options_to_uri(mongoc_uri_t *uri, bson_t *options TSRMLS_DC) /* {{{ */
16411640
{
16421641
bson_iter_t iter;
16431642
mongoc_read_concern_t *new_rc;
16441643
const mongoc_read_concern_t *old_rc;
16451644

1646-
if (!(old_rc = mongoc_client_get_read_concern(client))) {
1647-
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "Client does not have a read concern");
1645+
if (!(old_rc = mongoc_uri_get_read_concern(uri))) {
1646+
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "mongoc_uri_t does not have a read concern");
16481647

16491648
return false;
16501649
}
@@ -1666,20 +1665,20 @@ static bool php_phongo_apply_rc_options_to_client(mongoc_client_t *client, bson_
16661665
mongoc_read_concern_set_level(new_rc, str);
16671666
}
16681667

1669-
mongoc_client_set_read_concern(client, new_rc);
1668+
mongoc_uri_set_read_concern(uri, new_rc);
16701669
mongoc_read_concern_destroy(new_rc);
16711670

16721671
return true;
16731672
} /* }}} */
16741673

1675-
static bool php_phongo_apply_rp_options_to_client(mongoc_client_t *client, bson_t *options TSRMLS_DC) /* {{{ */
1674+
static bool php_phongo_apply_rp_options_to_uri(mongoc_uri_t *uri, bson_t *options TSRMLS_DC) /* {{{ */
16761675
{
16771676
bson_iter_t iter;
16781677
mongoc_read_prefs_t *new_rp;
16791678
const mongoc_read_prefs_t *old_rp;
16801679

1681-
if (!(old_rp = mongoc_client_get_read_prefs(client))) {
1682-
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "Client does not have a read preference");
1680+
if (!(old_rp = mongoc_uri_get_read_prefs_t(uri))) {
1681+
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "mongoc_uri_t does not have a read preference");
16831682

16841683
return false;
16851684
}
@@ -1751,21 +1750,21 @@ static bool php_phongo_apply_rp_options_to_client(mongoc_client_t *client, bson_
17511750
return false;
17521751
}
17531752

1754-
mongoc_client_set_read_prefs(client, new_rp);
1753+
mongoc_uri_set_read_prefs_t(uri, new_rp);
17551754
mongoc_read_prefs_destroy(new_rp);
17561755

17571756
return true;
17581757
} /* }}} */
17591758

1760-
static bool php_phongo_apply_wc_options_to_client(mongoc_client_t *client, bson_t *options TSRMLS_DC) /* {{{ */
1759+
static bool php_phongo_apply_wc_options_to_uri(mongoc_uri_t *uri, bson_t *options TSRMLS_DC) /* {{{ */
17611760
{
17621761
bson_iter_t iter;
17631762
int32_t wtimeoutms;
17641763
mongoc_write_concern_t *new_wc;
17651764
const mongoc_write_concern_t *old_wc;
17661765

1767-
if (!(old_wc = mongoc_client_get_write_concern(client))) {
1768-
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "Client does not have a write concern");
1766+
if (!(old_wc = mongoc_uri_get_write_concern(uri))) {
1767+
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "mongoc_uri_t does not have a write concern");
17691768

17701769
return false;
17711770
}
@@ -1859,7 +1858,7 @@ static bool php_phongo_apply_wc_options_to_client(mongoc_client_t *client, bson_
18591858
return false;
18601859
}
18611860

1862-
mongoc_client_set_write_concern(client, new_wc);
1861+
mongoc_uri_set_write_concern(uri, new_wc);
18631862
mongoc_write_concern_destroy(new_wc);
18641863

18651864
return true;
@@ -1986,6 +1985,13 @@ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
19861985
return false;
19871986
}
19881987

1988+
if (!php_phongo_apply_rc_options_to_uri(uri, bson_options TSRMLS_CC) ||
1989+
!php_phongo_apply_rp_options_to_uri(uri, bson_options TSRMLS_CC) ||
1990+
!php_phongo_apply_wc_options_to_uri(uri, bson_options TSRMLS_CC)) {
1991+
/* Exception should already have been thrown */
1992+
return false;
1993+
}
1994+
19891995
manager->client = php_phongo_make_mongo_client(uri, driverOptions TSRMLS_CC);
19901996
mongoc_uri_destroy(uri);
19911997

@@ -1994,13 +2000,6 @@ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
19942000
return false;
19952001
}
19962002

1997-
if (!php_phongo_apply_rc_options_to_client(manager->client, bson_options TSRMLS_CC) ||
1998-
!php_phongo_apply_rp_options_to_client(manager->client, bson_options TSRMLS_CC) ||
1999-
!php_phongo_apply_wc_options_to_client(manager->client, bson_options TSRMLS_CC)) {
2000-
/* Exception should already have been thrown */
2001-
return false;
2002-
}
2003-
20042003
return true;
20052004
} /* }}} */
20062005

0 commit comments

Comments
 (0)