@@ -351,117 +351,6 @@ void phongo_writeconcern_init(zval *return_value, const mongoc_write_concern_t *
351
351
}
352
352
/* }}} */
353
353
354
- int32_t phongo_bson_find_as_int32 (bson_t * bson , const char * key , int32_t fallback )
355
- {
356
- bson_iter_t iter ;
357
-
358
- if (bson_iter_init_find (& iter , bson , key ) && BSON_ITER_HOLDS_INT32 (& iter )) {
359
- return bson_iter_int32 (& iter );
360
- }
361
-
362
- return fallback ;
363
- }
364
-
365
- bool phongo_bson_find_as_bool (bson_t * bson , const char * key , bool fallback )
366
- {
367
- bson_iter_t iter ;
368
-
369
- if (bson_iter_init_find (& iter , bson , key ) && BSON_ITER_HOLDS_BOOL (& iter )) {
370
- return bson_iter_bool (& iter );
371
- }
372
-
373
- return fallback ;
374
- }
375
-
376
- void phongo_bson_iter_as_document (const bson_iter_t * iter , uint32_t * document_len , const uint8_t * * document )
377
- {
378
- * document = NULL ;
379
- * document_len = 0 ;
380
-
381
- if (BSON_ITER_HOLDS_DOCUMENT (iter ) || BSON_ITER_HOLDS_ARRAY (iter )) {
382
- memcpy (document_len , (iter -> raw + iter -> d1 ), sizeof (* document_len ));
383
- * document_len = BSON_UINT32_FROM_LE (* document_len );
384
- * document = (iter -> raw + iter -> d1 );
385
- }
386
- }
387
-
388
- bool phongo_query_init (php_phongo_query_t * query , bson_t * filter , bson_t * options TSRMLS_DC ) /* {{{ */
389
- {
390
- bson_iter_t iter ;
391
-
392
- if (options ) {
393
- query -> batch_size = phongo_bson_find_as_int32 (options , "batchSize" , 0 );
394
- query -> limit = phongo_bson_find_as_int32 (options , "limit" , 0 );
395
- query -> skip = phongo_bson_find_as_int32 (options , "skip" , 0 );
396
-
397
- query -> flags = 0 ;
398
- query -> flags |= phongo_bson_find_as_bool (options , "tailable" , false) ? MONGOC_QUERY_TAILABLE_CURSOR : 0 ;
399
- query -> flags |= phongo_bson_find_as_bool (options , "slaveOk" , false) ? MONGOC_QUERY_SLAVE_OK : 0 ;
400
- query -> flags |= phongo_bson_find_as_bool (options , "oplogReplay" , false) ? MONGOC_QUERY_OPLOG_REPLAY : 0 ;
401
- query -> flags |= phongo_bson_find_as_bool (options , "noCursorTimeout" , false) ? MONGOC_QUERY_NO_CURSOR_TIMEOUT : 0 ;
402
- query -> flags |= phongo_bson_find_as_bool (options , "awaitData" , false) ? MONGOC_QUERY_AWAIT_DATA : 0 ;
403
- query -> flags |= phongo_bson_find_as_bool (options , "exhaust" , false) ? MONGOC_QUERY_EXHAUST : 0 ;
404
- query -> flags |= phongo_bson_find_as_bool (options , "partial" , false) ? MONGOC_QUERY_PARTIAL : 0 ;
405
-
406
-
407
- if (bson_iter_init_find (& iter , options , "modifiers" )) {
408
- uint32_t len = 0 ;
409
- const uint8_t * data = NULL ;
410
-
411
- if (! (BSON_ITER_HOLDS_DOCUMENT (& iter ) || BSON_ITER_HOLDS_ARRAY (& iter ))) {
412
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected modifiers to be array or object, %d given" , bson_iter_type (& iter ));
413
- return false;
414
- }
415
-
416
- bson_iter_document (& iter , & len , & data );
417
- if (len ) {
418
- bson_t tmp ;
419
-
420
- bson_init_static (& tmp , data , len );
421
- bson_copy_to_excluding_noinit (& tmp , query -> query , "not-used-value" , NULL );
422
- bson_destroy (& tmp );
423
- }
424
- }
425
-
426
- if (bson_iter_init_find (& iter , options , "projection" )) {
427
- uint32_t len = 0 ;
428
- const uint8_t * data = NULL ;
429
-
430
- if (! (BSON_ITER_HOLDS_DOCUMENT (& iter ) || BSON_ITER_HOLDS_ARRAY (& iter ))) {
431
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected projection to be array or object, %d given" , bson_iter_type (& iter ));
432
- return false;
433
- }
434
-
435
- bson_iter_document (& iter , & len , & data );
436
- if (len ) {
437
- query -> selector = bson_new_from_data (data , len );
438
- }
439
- }
440
-
441
- if (bson_iter_init_find (& iter , options , "sort" )) {
442
- uint32_t len = 0 ;
443
- const uint8_t * data = NULL ;
444
-
445
- if (! (BSON_ITER_HOLDS_DOCUMENT (& iter ) || BSON_ITER_HOLDS_ARRAY (& iter ))) {
446
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected sort to be array or object, %d given" , bson_iter_type (& iter ));
447
- return false;
448
- }
449
-
450
- phongo_bson_iter_as_document (& iter , & len , & data );
451
- if (len ) {
452
- bson_t tmp ;
453
-
454
- bson_init_static (& tmp , data , len );
455
- bson_append_document (query -> query , "$orderby" , -1 , & tmp );
456
- bson_destroy (& tmp );
457
- }
458
- }
459
- }
460
-
461
- BSON_APPEND_DOCUMENT (query -> query , "$query" , filter );
462
- return true;
463
- } /* }}} */
464
-
465
354
zend_bool phongo_writeconcernerror_init (zval * return_value , bson_t * bson TSRMLS_DC ) /* {{{ */
466
355
{
467
356
bson_iter_t iter ;
@@ -716,7 +605,7 @@ int phongo_execute_query(zval *manager, const char *namespace, zval *zquery, zva
716
605
mongoc_collection_set_read_concern (collection , query -> read_concern );
717
606
}
718
607
719
- cursor = mongoc_collection_find (collection , query -> flags , query -> skip , query -> limit , query -> batch_size , query -> query , query -> selector , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ));
608
+ cursor = mongoc_collection_find_with_opts (collection , query -> filter , query -> opts , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ));
720
609
mongoc_collection_destroy (collection );
721
610
722
611
/* mongoc issues a warning we need to catch somehow */
0 commit comments