diff --git a/php_phongo.c b/php_phongo.c index 49c8deabb..c435a2417 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -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; @@ -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; diff --git a/php_phongo.h b/php_phongo.h index 59e780729..dce914df5 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -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); diff --git a/src/MongoDB/Manager.c b/src/MongoDB/Manager.c index ce51ddbfd..94f03fb16 100644 --- a/src/MongoDB/Manager.c +++ b/src/MongoDB/Manager.c @@ -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); } } /* }}} */ @@ -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); } } /* }}} */ diff --git a/tests/manager/manager-getreadpreference-001.phpt b/tests/manager/manager-getreadpreference-001.phpt index 7c0fd3d8f..137921ab0 100644 --- a/tests/manager/manager-getreadpreference-001.phpt +++ b/tests/manager/manager-getreadpreference-001.phpt @@ -29,36 +29,36 @@ foreach ($tests as $i => $test) { ?> ===DONE=== ---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"]=> @@ -75,7 +75,7 @@ array(2) { } } } -array(2) { +object(MongoDB\Driver\ReadPreference)#%d (%d) { ["mode"]=> int(2) ["tags"]=> @@ -92,7 +92,7 @@ array(2) { } } } -array(2) { +object(MongoDB\Driver\ReadPreference)#%d (%d) { ["mode"]=> int(2) ["tags"]=> diff --git a/tests/manager/manager-getwriteconcern-001.phpt b/tests/manager/manager-getwriteconcern-001.phpt index 4903ad76b..f50857059 100644 --- a/tests/manager/manager-getwriteconcern-001.phpt +++ b/tests/manager/manager-getwriteconcern-001.phpt @@ -34,8 +34,8 @@ foreach ($tests as $i => $test) { ?> ===DONE=== ---EXPECT-- -array(4) { +--EXPECTF-- +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["wmajority"]=> bool(false) ["wtimeout"]=> @@ -45,7 +45,7 @@ array(4) { ["journal"]=> NULL } -array(5) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["w"]=> int(1) ["wmajority"]=> @@ -57,7 +57,7 @@ array(5) { ["journal"]=> NULL } -array(5) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["w"]=> string(8) "majority" ["wmajority"]=> @@ -69,7 +69,7 @@ array(5) { ["journal"]=> NULL } -array(5) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["w"]=> int(1) ["wmajority"]=> @@ -81,7 +81,7 @@ array(5) { ["journal"]=> bool(true) } -array(5) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["w"]=> string(8) "majority" ["wmajority"]=> @@ -93,7 +93,7 @@ array(5) { ["journal"]=> bool(true) } -array(5) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["w"]=> int(1) ["wmajority"]=> @@ -105,7 +105,7 @@ array(5) { ["journal"]=> bool(false) } -array(4) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["wmajority"]=> bool(false) ["wtimeout"]=> @@ -115,7 +115,7 @@ array(4) { ["journal"]=> NULL } -array(4) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["wmajority"]=> bool(false) ["wtimeout"]=> @@ -125,7 +125,7 @@ array(4) { ["journal"]=> NULL } -array(5) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["w"]=> int(2) ["wmajority"]=> @@ -137,7 +137,7 @@ array(5) { ["journal"]=> NULL } -array(5) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["w"]=> string(8) "majority" ["wmajority"]=> @@ -149,7 +149,7 @@ array(5) { ["journal"]=> NULL } -array(5) { +object(MongoDB\Driver\WriteConcern)#%d (%d) { ["w"]=> string(12) "customTagSet" ["wmajority"]=>