Skip to content

Commit e06c96d

Browse files
committed
Merge pull request #330
2 parents aa931f3 + 05fcc2e commit e06c96d

File tree

12 files changed

+269
-140
lines changed

12 files changed

+269
-140
lines changed

php_phongo.c

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain,
224224
/* }}} */
225225

226226
/* {{{ Init objects */
227-
static void phongo_cursor_init(zval *return_value, mongoc_cursor_t *cursor, mongoc_client_t *client TSRMLS_DC) /* {{{ */
227+
static void phongo_cursor_init(zval *return_value, zval *manager, mongoc_cursor_t *cursor TSRMLS_DC) /* {{{ */
228228
{
229229
php_phongo_cursor_t *intern;
230230

@@ -233,18 +233,32 @@ static void phongo_cursor_init(zval *return_value, mongoc_cursor_t *cursor, mong
233233
intern = Z_CURSOR_OBJ_P(return_value);
234234
intern->cursor = cursor;
235235
intern->server_id = mongoc_cursor_get_hint(cursor);
236-
intern->client = client;
236+
intern->client = Z_MANAGER_OBJ_P(manager)->client;
237+
238+
#if PHP_VERSION_ID >= 70000
239+
ZVAL_COPY(&intern->manager, manager);
240+
#else
241+
Z_ADDREF_P(manager);
242+
intern->manager = manager;
243+
#endif
237244
} /* }}} */
238245

239-
void phongo_server_init(zval *return_value, mongoc_client_t *client, int server_id TSRMLS_DC) /* {{{ */
246+
void phongo_server_init(zval *return_value, zval *manager, int server_id TSRMLS_DC) /* {{{ */
240247
{
241248
php_phongo_server_t *server;
242249

243250
object_init_ex(return_value, php_phongo_server_ce);
244251

245252
server = Z_SERVER_OBJ_P(return_value);
246-
server->client = client;
247253
server->server_id = server_id;
254+
server->client = Z_MANAGER_OBJ_P(manager)->client;
255+
256+
#if PHP_VERSION_ID >= 70000
257+
ZVAL_COPY(&server->manager, manager);
258+
#else
259+
Z_ADDREF_P(manager);
260+
server->manager = manager;
261+
#endif
248262
}
249263
/* }}} */
250264

@@ -467,16 +481,23 @@ zend_bool phongo_writeerror_init(zval *return_value, bson_t *bson TSRMLS_DC) /*
467481
return true;
468482
} /* }}} */
469483

470-
php_phongo_writeresult_t *phongo_writeresult_init(zval *return_value, bson_t *reply, mongoc_client_t *client, int server_id TSRMLS_DC) /* {{{ */
484+
php_phongo_writeresult_t *phongo_writeresult_init(zval *return_value, bson_t *reply, zval *manager, int server_id TSRMLS_DC) /* {{{ */
471485
{
472486
php_phongo_writeresult_t *writeresult;
473487

474488
object_init_ex(return_value, php_phongo_writeresult_ce);
475489

476490
writeresult = Z_WRITERESULT_OBJ_P(return_value);
477491
writeresult->reply = bson_copy(reply);
478-
writeresult->client = client;
479492
writeresult->server_id = server_id;
493+
writeresult->client = Z_MANAGER_OBJ_P(manager)->client;
494+
495+
#if PHP_VERSION_ID >= 70000
496+
ZVAL_COPY(&writeresult->manager, manager);
497+
#else
498+
Z_ADDREF_P(manager);
499+
writeresult->manager = manager;
500+
#endif
480501

481502
return writeresult;
482503
} /* }}} */
@@ -506,15 +527,18 @@ mongoc_bulk_operation_t *phongo_bulkwrite_init(zend_bool ordered) { /* {{{ */
506527
return mongoc_bulk_operation_new(ordered);
507528
} /* }}} */
508529

509-
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) /* {{{ */
530+
bool phongo_execute_write(zval *manager, 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) /* {{{ */
510531
{
532+
mongoc_client_t *client;
511533
bson_error_t error;
512534
char *dbname;
513535
char *collname;
514536
int success;
515537
bson_t reply = BSON_INITIALIZER;
516538
php_phongo_writeresult_t *writeresult;
517539

540+
client = Z_MANAGER_OBJ_P(manager)->client;
541+
518542
if (!phongo_split_namespace(namespace, &dbname, &collname)) {
519543
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s: %s", "Invalid namespace provided", namespace);
520544
return false;
@@ -553,7 +577,7 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, mongoc
553577
return false;
554578
}
555579

556-
writeresult = phongo_writeresult_init(return_value, &reply, client, bulk->hint TSRMLS_CC);
580+
writeresult = phongo_writeresult_init(return_value, &reply, manager, bulk->hint TSRMLS_CC);
557581
writeresult->write_concern = mongoc_write_concern_copy(write_concern);
558582

559583
/* The Write failed */
@@ -571,14 +595,17 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, mongoc
571595
return success;
572596
} /* }}} */
573597

574-
int phongo_execute_query(mongoc_client_t *client, const char *namespace, const php_phongo_query_t *query, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC) /* {{{ */
598+
int phongo_execute_query(zval *manager, const char *namespace, const php_phongo_query_t *query, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC) /* {{{ */
575599
{
600+
mongoc_client_t *client;
576601
const bson_t *doc = NULL;
577602
mongoc_cursor_t *cursor;
578603
char *dbname;
579604
char *collname;
580605
mongoc_collection_t *collection;
581606

607+
client = Z_MANAGER_OBJ_P(manager)->client;
608+
582609
if (!phongo_split_namespace(namespace, &dbname, &collname)) {
583610
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s: %s", "Invalid namespace provided", namespace);
584611
return false;
@@ -626,17 +653,19 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, const p
626653
return true;
627654
}
628655

629-
phongo_cursor_init(return_value, cursor, client TSRMLS_CC);
656+
phongo_cursor_init(return_value, manager, cursor TSRMLS_CC);
630657
return true;
631658
} /* }}} */
632659

633-
int phongo_execute_command(mongoc_client_t *client, const char *db, const bson_t *command, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC) /* {{{ */
660+
int phongo_execute_command(zval *manager, const char *db, const bson_t *command, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC) /* {{{ */
634661
{
662+
mongoc_client_t *client;
635663
mongoc_cursor_t *cursor;
636664
const bson_t *doc;
637665
bson_iter_t iter;
638666
bson_iter_t child;
639667

668+
client = Z_MANAGER_OBJ_P(manager)->client;
640669

641670
cursor = mongoc_client_command(client, db, MONGOC_QUERY_NONE, 0, 1, 0, command, NULL, read_preference);
642671
if (server_id > 0) {
@@ -702,7 +731,7 @@ int phongo_execute_command(mongoc_client_t *client, const char *db, const bson_t
702731
mongoc_cursor_next(cursor, &doc);
703732
}
704733

705-
phongo_cursor_init(return_value, cursor, client TSRMLS_CC);
734+
phongo_cursor_init(return_value, manager, cursor TSRMLS_CC);
706735
return true;
707736
} /* }}} */
708737

php_phongo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ void phongo_throw_exception_from_bson_error_t(bson_error_t *error TSRMLS_DC);
114114

115115
PHONGO_API zend_object_handlers *phongo_get_std_object_handlers(void);
116116

117-
void phongo_server_init (zval *return_value, mongoc_client_t *client, int server_id TSRMLS_DC);
117+
void phongo_server_init (zval *return_value, zval *manager, int server_id TSRMLS_DC);
118118
void phongo_readconcern_init (zval *return_value, const mongoc_read_concern_t *read_concern TSRMLS_DC);
119119
void phongo_readpreference_init (zval *return_value, const mongoc_read_prefs_t *read_prefs TSRMLS_DC);
120120
void phongo_writeconcern_init (zval *return_value, const mongoc_write_concern_t *write_concern TSRMLS_DC);
121121
bool phongo_query_init (php_phongo_query_t *query, bson_t *filter, bson_t *options TSRMLS_DC);
122122
mongoc_bulk_operation_t* phongo_bulkwrite_init (zend_bool ordered);
123-
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);
124-
int phongo_execute_command (mongoc_client_t *client, const char *db, const bson_t *command, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC);
125-
int phongo_execute_query (mongoc_client_t *client, const char *namespace, const php_phongo_query_t *query, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC);
123+
bool phongo_execute_write (zval *manager, 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);
124+
int phongo_execute_command (zval *manager, const char *db, const bson_t *command, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC);
125+
int phongo_execute_query (zval *manager, const char *namespace, const php_phongo_query_t *query, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC);
126126

127127
mongoc_stream_t* phongo_stream_initiator (const mongoc_uri_t *uri, const mongoc_host_list_t *host, void *user_data, bson_error_t *error);
128128
const mongoc_read_concern_t* phongo_read_concern_from_zval (zval *zread_concern TSRMLS_DC);

0 commit comments

Comments
 (0)