Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain,
/* }}} */

/* {{{ Init objects */
void phongo_cursor_init(zval *return_value, mongoc_cursor_t *cursor, mongoc_client_t *client TSRMLS_DC) /* {{{ */
static void phongo_cursor_init(zval *return_value, mongoc_cursor_t *cursor, mongoc_client_t *client TSRMLS_DC) /* {{{ */
{
php_phongo_cursor_t *intern;

Expand All @@ -294,6 +294,28 @@ void phongo_server_init(zval *return_value, mongoc_client_t *client, int server_
}
/* }}} */

void phongo_readpreference_init(zval *return_value, const mongoc_read_prefs_t *read_prefs TSRMLS_DC) /* {{{ */
{
php_phongo_readpreference_t *intern;

object_init_ex(return_value, php_phongo_readpreference_ce);

intern = (php_phongo_readpreference_t *)zend_object_store_get_object(return_value TSRMLS_CC);
intern->read_preference = mongoc_read_prefs_copy(read_prefs);
}
/* }}} */

void phongo_writeconcern_init(zval *return_value, const mongoc_write_concern_t *write_concern TSRMLS_DC) /* {{{ */
{
php_phongo_writeconcern_t *intern;

object_init_ex(return_value, php_phongo_writeconcern_ce);

intern = (php_phongo_writeconcern_t *)zend_object_store_get_object(return_value TSRMLS_CC);
intern->write_concern = mongoc_write_concern_copy(write_concern);
}
/* }}} */

bool phongo_query_init(php_phongo_query_t *query, zval *filter, zval *options TSRMLS_DC) /* {{{ */
{
zval *zquery = NULL;
Expand Down
2 changes: 2 additions & 0 deletions php_phongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ PHONGO_API zval* phongo_throw_exception(php_phongo_error_domain_t domain TSRMLS_
PHONGO_API zend_object_handlers *phongo_get_std_object_handlers(void);

void phongo_server_init (zval *return_value, mongoc_client_t *client, int server_id TSRMLS_DC);
void phongo_readpreference_init (zval *return_value, const mongoc_read_prefs_t *read_prefs TSRMLS_DC);
void phongo_writeconcern_init (zval *return_value, const mongoc_write_concern_t *write_concern TSRMLS_DC);
bool phongo_query_init (php_phongo_query_t *query, zval *filter, zval *options TSRMLS_DC);
mongoc_bulk_operation_t* phongo_bulkwrite_init (zend_bool ordered);
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);
Expand Down
4 changes: 2 additions & 2 deletions src/MongoDB/Manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ PHP_METHOD(Manager, getReadPreference)
}

if (return_value_used) {
php_phongo_read_preference_to_zval(return_value, mongoc_client_get_read_prefs(intern->client));
phongo_readpreference_init(return_value, mongoc_client_get_read_prefs(intern->client) TSRMLS_CC);
}
}
/* }}} */
Expand Down Expand Up @@ -341,7 +341,7 @@ PHP_METHOD(Manager, getWriteConcern)
}

if (return_value_used) {
php_phongo_write_concern_to_zval(return_value, mongoc_client_get_write_concern(intern->client));
phongo_writeconcern_init(return_value, mongoc_client_get_write_concern(intern->client) TSRMLS_CC);
}
}
/* }}} */
Expand Down
16 changes: 8 additions & 8 deletions tests/manager/manager-getreadpreference-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,36 @@ foreach ($tests as $i => $test) {
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(2) {
--EXPECTF--
object(MongoDB\Driver\ReadPreference)#%d (%d) {
["mode"]=>
int(1)
["tags"]=>
array(0) {
}
}
array(2) {
object(MongoDB\Driver\ReadPreference)#%d (%d) {
["mode"]=>
int(2)
["tags"]=>
array(0) {
}
}
array(2) {
object(MongoDB\Driver\ReadPreference)#%d (%d) {
["mode"]=>
int(5)
["tags"]=>
array(0) {
}
}
array(2) {
object(MongoDB\Driver\ReadPreference)#%d (%d) {
["mode"]=>
int(6)
["tags"]=>
array(0) {
}
}
array(2) {
object(MongoDB\Driver\ReadPreference)#%d (%d) {
["mode"]=>
int(2)
["tags"]=>
Expand All @@ -75,7 +75,7 @@ array(2) {
}
}
}
array(2) {
object(MongoDB\Driver\ReadPreference)#%d (%d) {
["mode"]=>
int(2)
["tags"]=>
Expand All @@ -92,7 +92,7 @@ array(2) {
}
}
}
array(2) {
object(MongoDB\Driver\ReadPreference)#%d (%d) {
["mode"]=>
int(2)
["tags"]=>
Expand Down
24 changes: 12 additions & 12 deletions tests/manager/manager-getwriteconcern-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ foreach ($tests as $i => $test) {
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
array(4) {
--EXPECTF--
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand All @@ -45,7 +45,7 @@ array(4) {
["journal"]=>
NULL
}
array(5) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
int(1)
["wmajority"]=>
Expand All @@ -57,7 +57,7 @@ array(5) {
["journal"]=>
NULL
}
array(5) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(8) "majority"
["wmajority"]=>
Expand All @@ -69,7 +69,7 @@ array(5) {
["journal"]=>
NULL
}
array(5) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
int(1)
["wmajority"]=>
Expand All @@ -81,7 +81,7 @@ array(5) {
["journal"]=>
bool(true)
}
array(5) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(8) "majority"
["wmajority"]=>
Expand All @@ -93,7 +93,7 @@ array(5) {
["journal"]=>
bool(true)
}
array(5) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
int(1)
["wmajority"]=>
Expand All @@ -105,7 +105,7 @@ array(5) {
["journal"]=>
bool(false)
}
array(4) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand All @@ -115,7 +115,7 @@ array(4) {
["journal"]=>
NULL
}
array(4) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wmajority"]=>
bool(false)
["wtimeout"]=>
Expand All @@ -125,7 +125,7 @@ array(4) {
["journal"]=>
NULL
}
array(5) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
int(2)
["wmajority"]=>
Expand All @@ -137,7 +137,7 @@ array(5) {
["journal"]=>
NULL
}
array(5) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(8) "majority"
["wmajority"]=>
Expand All @@ -149,7 +149,7 @@ array(5) {
["journal"]=>
NULL
}
array(5) {
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(12) "customTagSet"
["wmajority"]=>
Expand Down