Skip to content

Commit 81c7634

Browse files
committed
PHPC-417: Return value objects from Manager RP/WC getters
1 parent fb2ab50 commit 81c7634

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

php_phongo.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,28 @@ void phongo_server_init(zval *return_value, mongoc_client_t *client, int server_
294294
}
295295
/* }}} */
296296

297+
void phongo_readpreference_init(zval *return_value, const mongoc_read_prefs_t *read_prefs TSRMLS_DC) /* {{{ */
298+
{
299+
php_phongo_readpreference_t *intern;
300+
301+
object_init_ex(return_value, php_phongo_readpreference_ce);
302+
303+
intern = (php_phongo_readpreference_t *)zend_object_store_get_object(return_value TSRMLS_CC);
304+
intern->read_preference = mongoc_read_prefs_copy(read_prefs);
305+
}
306+
/* }}} */
307+
308+
void phongo_writeconcern_init(zval *return_value, const mongoc_write_concern_t *write_concern TSRMLS_DC) /* {{{ */
309+
{
310+
php_phongo_writeconcern_t *intern;
311+
312+
object_init_ex(return_value, php_phongo_writeconcern_ce);
313+
314+
intern = (php_phongo_writeconcern_t *)zend_object_store_get_object(return_value TSRMLS_CC);
315+
intern->write_concern = mongoc_write_concern_copy(write_concern);
316+
}
317+
/* }}} */
318+
297319
bool phongo_query_init(php_phongo_query_t *query, zval *filter, zval *options TSRMLS_DC) /* {{{ */
298320
{
299321
zval *zquery = NULL;

php_phongo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ PHONGO_API zval* phongo_throw_exception(php_phongo_error_domain_t domain TSRMLS_
111111
PHONGO_API zend_object_handlers *phongo_get_std_object_handlers(void);
112112

113113
void phongo_server_init (zval *return_value, mongoc_client_t *client, int server_id TSRMLS_DC);
114+
void phongo_readpreference_init (zval *return_value, const mongoc_read_prefs_t *read_prefs TSRMLS_DC);
115+
void phongo_writeconcern_init (zval *return_value, const mongoc_write_concern_t *write_concern TSRMLS_DC);
114116
bool phongo_query_init (php_phongo_query_t *query, zval *filter, zval *options TSRMLS_DC);
115117
mongoc_bulk_operation_t* phongo_bulkwrite_init (zend_bool ordered);
116118
bool phongo_execute_write (mongoc_client_t *client, const char *namespace, mongoc_bulk_operation_t *bulk, const mongoc_write_concern_t *write_concern, int server_id, zval *return_value, int return_value_used TSRMLS_DC);

src/MongoDB/Manager.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ PHP_METHOD(Manager, getReadPreference)
290290
}
291291

292292
if (return_value_used) {
293-
php_phongo_read_preference_to_zval(return_value, mongoc_client_get_read_prefs(intern->client));
293+
phongo_readpreference_init(return_value, mongoc_client_get_read_prefs(intern->client) TSRMLS_CC);
294294
}
295295
}
296296
/* }}} */
@@ -341,7 +341,7 @@ PHP_METHOD(Manager, getWriteConcern)
341341
}
342342

343343
if (return_value_used) {
344-
php_phongo_write_concern_to_zval(return_value, mongoc_client_get_write_concern(intern->client));
344+
phongo_writeconcern_init(return_value, mongoc_client_get_write_concern(intern->client) TSRMLS_CC);
345345
}
346346
}
347347
/* }}} */

tests/manager/manager-getreadpreference-001.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,36 @@ foreach ($tests as $i => $test) {
2929
?>
3030
===DONE===
3131
<?php exit(0); ?>
32-
--EXPECT--
33-
array(2) {
32+
--EXPECTF--
33+
object(MongoDB\Driver\ReadPreference)#%d (%d) {
3434
["mode"]=>
3535
int(1)
3636
["tags"]=>
3737
array(0) {
3838
}
3939
}
40-
array(2) {
40+
object(MongoDB\Driver\ReadPreference)#%d (%d) {
4141
["mode"]=>
4242
int(2)
4343
["tags"]=>
4444
array(0) {
4545
}
4646
}
47-
array(2) {
47+
object(MongoDB\Driver\ReadPreference)#%d (%d) {
4848
["mode"]=>
4949
int(5)
5050
["tags"]=>
5151
array(0) {
5252
}
5353
}
54-
array(2) {
54+
object(MongoDB\Driver\ReadPreference)#%d (%d) {
5555
["mode"]=>
5656
int(6)
5757
["tags"]=>
5858
array(0) {
5959
}
6060
}
61-
array(2) {
61+
object(MongoDB\Driver\ReadPreference)#%d (%d) {
6262
["mode"]=>
6363
int(2)
6464
["tags"]=>
@@ -75,7 +75,7 @@ array(2) {
7575
}
7676
}
7777
}
78-
array(2) {
78+
object(MongoDB\Driver\ReadPreference)#%d (%d) {
7979
["mode"]=>
8080
int(2)
8181
["tags"]=>
@@ -92,7 +92,7 @@ array(2) {
9292
}
9393
}
9494
}
95-
array(2) {
95+
object(MongoDB\Driver\ReadPreference)#%d (%d) {
9696
["mode"]=>
9797
int(2)
9898
["tags"]=>

tests/manager/manager-getwriteconcern-001.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ foreach ($tests as $i => $test) {
3434
?>
3535
===DONE===
3636
<?php exit(0); ?>
37-
--EXPECT--
38-
array(4) {
37+
--EXPECTF--
38+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
3939
["wmajority"]=>
4040
bool(false)
4141
["wtimeout"]=>
@@ -45,7 +45,7 @@ array(4) {
4545
["journal"]=>
4646
NULL
4747
}
48-
array(5) {
48+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
4949
["w"]=>
5050
int(1)
5151
["wmajority"]=>
@@ -57,7 +57,7 @@ array(5) {
5757
["journal"]=>
5858
NULL
5959
}
60-
array(5) {
60+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
6161
["w"]=>
6262
string(8) "majority"
6363
["wmajority"]=>
@@ -69,7 +69,7 @@ array(5) {
6969
["journal"]=>
7070
NULL
7171
}
72-
array(5) {
72+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
7373
["w"]=>
7474
int(1)
7575
["wmajority"]=>
@@ -81,7 +81,7 @@ array(5) {
8181
["journal"]=>
8282
bool(true)
8383
}
84-
array(5) {
84+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
8585
["w"]=>
8686
string(8) "majority"
8787
["wmajority"]=>
@@ -93,7 +93,7 @@ array(5) {
9393
["journal"]=>
9494
bool(true)
9595
}
96-
array(5) {
96+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
9797
["w"]=>
9898
int(1)
9999
["wmajority"]=>
@@ -105,7 +105,7 @@ array(5) {
105105
["journal"]=>
106106
bool(false)
107107
}
108-
array(4) {
108+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
109109
["wmajority"]=>
110110
bool(false)
111111
["wtimeout"]=>
@@ -115,7 +115,7 @@ array(4) {
115115
["journal"]=>
116116
NULL
117117
}
118-
array(4) {
118+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
119119
["wmajority"]=>
120120
bool(false)
121121
["wtimeout"]=>
@@ -125,7 +125,7 @@ array(4) {
125125
["journal"]=>
126126
NULL
127127
}
128-
array(5) {
128+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
129129
["w"]=>
130130
int(2)
131131
["wmajority"]=>
@@ -137,7 +137,7 @@ array(5) {
137137
["journal"]=>
138138
NULL
139139
}
140-
array(5) {
140+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
141141
["w"]=>
142142
string(8) "majority"
143143
["wmajority"]=>
@@ -149,7 +149,7 @@ array(5) {
149149
["journal"]=>
150150
NULL
151151
}
152-
array(5) {
152+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
153153
["w"]=>
154154
string(12) "customTagSet"
155155
["wmajority"]=>

0 commit comments

Comments
 (0)