@@ -234,7 +234,7 @@ static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain,
234
234
/* }}} */
235
235
236
236
/* {{{ Init objects */
237
- static void phongo_cursor_init (zval * return_value , mongoc_cursor_t * cursor , mongoc_client_t * client , zval * readPreference TSRMLS_DC ) /* {{{ */
237
+ static void phongo_cursor_init (zval * return_value , zval * manager , mongoc_cursor_t * cursor , zval * readPreference TSRMLS_DC ) /* {{{ */
238
238
{
239
239
php_phongo_cursor_t * intern ;
240
240
@@ -243,7 +243,14 @@ static void phongo_cursor_init(zval *return_value, mongoc_cursor_t *cursor, mong
243
243
intern = Z_CURSOR_OBJ_P (return_value );
244
244
intern -> cursor = cursor ;
245
245
intern -> server_id = mongoc_cursor_get_hint (cursor );
246
- intern -> client = client ;
246
+ intern -> client = Z_MANAGER_OBJ_P (manager )-> client ;
247
+
248
+ #if PHP_VERSION_ID >= 70000
249
+ ZVAL_COPY (& intern -> manager , manager );
250
+ #else
251
+ Z_ADDREF_P (manager );
252
+ intern -> manager = manager ;
253
+ #endif
247
254
248
255
if (readPreference ) {
249
256
#if PHP_VERSION_ID >= 70000
@@ -255,11 +262,11 @@ static void phongo_cursor_init(zval *return_value, mongoc_cursor_t *cursor, mong
255
262
}
256
263
} /* }}} */
257
264
258
- static void phongo_cursor_init_for_command (zval * return_value , mongoc_cursor_t * cursor , mongoc_client_t * client , const char * db , zval * command , zval * readPreference TSRMLS_DC ) /* {{{ */
265
+ static void phongo_cursor_init_for_command (zval * return_value , zval * manager , mongoc_cursor_t * cursor , const char * db , zval * command , zval * readPreference TSRMLS_DC ) /* {{{ */
259
266
{
260
267
php_phongo_cursor_t * intern ;
261
268
262
- phongo_cursor_init (return_value , cursor , client , readPreference TSRMLS_CC );
269
+ phongo_cursor_init (return_value , manager , cursor , readPreference TSRMLS_CC );
263
270
intern = Z_CURSOR_OBJ_P (return_value );
264
271
265
272
intern -> database = estrdup (db );
@@ -272,11 +279,11 @@ static void phongo_cursor_init_for_command(zval *return_value, mongoc_cursor_t *
272
279
#endif
273
280
} /* }}} */
274
281
275
- static void phongo_cursor_init_for_query (zval * return_value , mongoc_cursor_t * cursor , mongoc_client_t * client , const char * namespace , zval * query , zval * readPreference TSRMLS_DC ) /* {{{ */
282
+ static void phongo_cursor_init_for_query (zval * return_value , zval * manager , mongoc_cursor_t * cursor , const char * namespace , zval * query , zval * readPreference TSRMLS_DC ) /* {{{ */
276
283
{
277
284
php_phongo_cursor_t * intern ;
278
285
279
- phongo_cursor_init (return_value , cursor , client , readPreference TSRMLS_CC );
286
+ phongo_cursor_init (return_value , manager , cursor , readPreference TSRMLS_CC );
280
287
intern = Z_CURSOR_OBJ_P (return_value );
281
288
282
289
/* namespace has already been validated by phongo_execute_query() */
@@ -290,15 +297,22 @@ static void phongo_cursor_init_for_query(zval *return_value, mongoc_cursor_t *cu
290
297
#endif
291
298
} /* }}} */
292
299
293
- void phongo_server_init (zval * return_value , mongoc_client_t * client , int server_id TSRMLS_DC ) /* {{{ */
300
+ void phongo_server_init (zval * return_value , zval * manager , int server_id TSRMLS_DC ) /* {{{ */
294
301
{
295
302
php_phongo_server_t * server ;
296
303
297
304
object_init_ex (return_value , php_phongo_server_ce );
298
305
299
306
server = Z_SERVER_OBJ_P (return_value );
300
- server -> client = client ;
301
307
server -> server_id = server_id ;
308
+ server -> client = Z_MANAGER_OBJ_P (manager )-> client ;
309
+
310
+ #if PHP_VERSION_ID >= 70000
311
+ ZVAL_COPY (& server -> manager , manager );
312
+ #else
313
+ Z_ADDREF_P (manager );
314
+ server -> manager = manager ;
315
+ #endif
302
316
}
303
317
/* }}} */
304
318
@@ -521,16 +535,23 @@ zend_bool phongo_writeerror_init(zval *return_value, bson_t *bson TSRMLS_DC) /*
521
535
return true;
522
536
} /* }}} */
523
537
524
- php_phongo_writeresult_t * phongo_writeresult_init (zval * return_value , bson_t * reply , mongoc_client_t * client , int server_id TSRMLS_DC ) /* {{{ */
538
+ php_phongo_writeresult_t * phongo_writeresult_init (zval * return_value , bson_t * reply , zval * manager , int server_id TSRMLS_DC ) /* {{{ */
525
539
{
526
540
php_phongo_writeresult_t * writeresult ;
527
541
528
542
object_init_ex (return_value , php_phongo_writeresult_ce );
529
543
530
544
writeresult = Z_WRITERESULT_OBJ_P (return_value );
531
545
writeresult -> reply = bson_copy (reply );
532
- writeresult -> client = client ;
533
546
writeresult -> server_id = server_id ;
547
+ writeresult -> client = Z_MANAGER_OBJ_P (manager )-> client ;
548
+
549
+ #if PHP_VERSION_ID >= 70000
550
+ ZVAL_COPY (& writeresult -> manager , manager );
551
+ #else
552
+ Z_ADDREF_P (manager );
553
+ writeresult -> manager = manager ;
554
+ #endif
534
555
535
556
return writeresult ;
536
557
} /* }}} */
@@ -560,14 +581,17 @@ mongoc_bulk_operation_t *phongo_bulkwrite_init(zend_bool ordered) { /* {{{ */
560
581
return mongoc_bulk_operation_new (ordered );
561
582
} /* }}} */
562
583
563
- bool phongo_execute_write (mongoc_client_t * client , const char * namespace , php_phongo_bulkwrite_t * bulk_write , const mongoc_write_concern_t * write_concern , int server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
584
+ bool phongo_execute_write (zval * manager , const char * namespace , php_phongo_bulkwrite_t * bulk_write , const mongoc_write_concern_t * write_concern , int server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
564
585
{
586
+ mongoc_client_t * client ;
565
587
bson_error_t error ;
566
588
int success ;
567
589
bson_t reply = BSON_INITIALIZER ;
568
590
mongoc_bulk_operation_t * bulk = bulk_write -> bulk ;
569
591
php_phongo_writeresult_t * writeresult ;
570
592
593
+ client = Z_MANAGER_OBJ_P (manager )-> client ;
594
+
571
595
/* Since BulkWrite objects can currently be executed multiple times, ensure
572
596
* that the database and collection name are freed before we overwrite them.
573
597
* This may be removed once PHPC-676 is implemented. */
@@ -615,7 +639,7 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, php_ph
615
639
return false;
616
640
}
617
641
618
- writeresult = phongo_writeresult_init (return_value , & reply , client , mongoc_bulk_operation_get_hint (bulk ) TSRMLS_CC );
642
+ writeresult = phongo_writeresult_init (return_value , & reply , manager , mongoc_bulk_operation_get_hint (bulk ) TSRMLS_CC );
619
643
writeresult -> write_concern = mongoc_write_concern_copy (write_concern );
620
644
621
645
/* The Write failed */
@@ -659,14 +683,17 @@ static bool phongo_advance_cursor_and_check_for_error(mongoc_cursor_t *cursor TS
659
683
return true;
660
684
}
661
685
662
- int phongo_execute_query (mongoc_client_t * client , const char * namespace , zval * zquery , zval * zreadPreference , int server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
686
+ int phongo_execute_query (zval * manager , const char * namespace , zval * zquery , zval * zreadPreference , int server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
663
687
{
688
+ mongoc_client_t * client ;
664
689
const php_phongo_query_t * query ;
665
690
mongoc_cursor_t * cursor ;
666
691
char * dbname ;
667
692
char * collname ;
668
693
mongoc_collection_t * collection ;
669
694
695
+ client = Z_MANAGER_OBJ_P (manager )-> client ;
696
+
670
697
if (!phongo_split_namespace (namespace , & dbname , & collname )) {
671
698
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s: %s" , "Invalid namespace provided" , namespace );
672
699
return false;
@@ -704,16 +731,18 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
704
731
return true;
705
732
}
706
733
707
- phongo_cursor_init_for_query (return_value , cursor , client , namespace , zquery , zreadPreference TSRMLS_CC );
734
+ phongo_cursor_init_for_query (return_value , manager , cursor , namespace , zquery , zreadPreference TSRMLS_CC );
708
735
return true;
709
736
} /* }}} */
710
737
711
- int phongo_execute_command (mongoc_client_t * client , const char * db , zval * zcommand , zval * zreadPreference , int server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
738
+ int phongo_execute_command (zval * manager , const char * db , zval * zcommand , zval * zreadPreference , int server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
712
739
{
740
+ mongoc_client_t * client ;
713
741
const php_phongo_command_t * command ;
714
742
mongoc_cursor_t * cursor ;
715
743
bson_iter_t iter ;
716
744
745
+ client = Z_MANAGER_OBJ_P (manager )-> client ;
717
746
command = Z_COMMAND_OBJ_P (zcommand );
718
747
719
748
cursor = mongoc_client_command (client , db , MONGOC_QUERY_NONE , 0 , 1 , 0 , command -> bson , NULL , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ));
@@ -745,11 +774,11 @@ int phongo_execute_command(mongoc_client_t *client, const char *db, zval *zcomma
745
774
return false;
746
775
}
747
776
748
- phongo_cursor_init_for_command (return_value , cmd_cursor , client , db , zcommand , zreadPreference TSRMLS_CC );
777
+ phongo_cursor_init_for_command (return_value , manager , cmd_cursor , db , zcommand , zreadPreference TSRMLS_CC );
749
778
return true;
750
779
}
751
780
752
- phongo_cursor_init_for_command (return_value , cursor , client , db , zcommand , zreadPreference TSRMLS_CC );
781
+ phongo_cursor_init_for_command (return_value , manager , cursor , db , zcommand , zreadPreference TSRMLS_CC );
753
782
return true;
754
783
} /* }}} */
755
784
@@ -1847,9 +1876,11 @@ static bool php_phongo_apply_wc_options_to_uri(mongoc_uri_t *uri, bson_t *option
1847
1876
static mongoc_client_t * php_phongo_make_mongo_client (php_phongo_manager_t * manager , const mongoc_uri_t * uri , zval * driverOptions TSRMLS_DC ) /* {{{ */
1848
1877
{
1849
1878
#if PHP_VERSION_ID >= 70000
1850
- zval * tmp ;
1879
+ zval * zdebug = NULL ;
1880
+ zval * zcontext = NULL ;
1851
1881
#else
1852
- zval * * tmp ;
1882
+ zval * * zdebug = NULL ;
1883
+ zval * * zcontext = NULL ;
1853
1884
#endif
1854
1885
php_stream_context * ctx = NULL ;
1855
1886
const char * mech , * mongoc_version , * bson_version ;
@@ -1858,30 +1889,31 @@ static mongoc_client_t *php_phongo_make_mongo_client(php_phongo_manager_t *manag
1858
1889
ENTRY ;
1859
1890
1860
1891
#if PHP_VERSION_ID >= 70000
1861
- if (driverOptions && (tmp = zend_hash_str_find (Z_ARRVAL_P (driverOptions ), "debug" , sizeof ("debug" )- 1 )) != NULL ) {
1892
+ if (driverOptions && (zdebug = zend_hash_str_find (Z_ARRVAL_P (driverOptions ), "debug" , sizeof ("debug" )- 1 )) != NULL ) {
1862
1893
zend_string * key = zend_string_init (PHONGO_DEBUG_INI , sizeof (PHONGO_DEBUG_INI )- 1 , 0 );
1863
- zend_string * value_str = zval_get_string (tmp );
1894
+ zend_string * value_str = zval_get_string (zdebug );
1864
1895
zend_alter_ini_entry_ex (key , value_str , PHP_INI_USER , PHP_INI_STAGE_RUNTIME , 0 );
1865
1896
zend_string_release (key );
1866
1897
zend_string_release (value_str );
1867
1898
}
1868
1899
#else
1869
- if (driverOptions && zend_hash_find (Z_ARRVAL_P (driverOptions ), "debug" , strlen ("debug" ) + 1 , (void * * )& tmp ) == SUCCESS ) {
1870
- convert_to_string (* tmp );
1900
+ if (driverOptions && zend_hash_find (Z_ARRVAL_P (driverOptions ), "debug" , strlen ("debug" ) + 1 , (void * * )& zdebug ) == SUCCESS ) {
1901
+ convert_to_string (* zdebug );
1871
1902
1872
- zend_alter_ini_entry_ex ((char * )PHONGO_DEBUG_INI , sizeof (PHONGO_DEBUG_INI ), Z_STRVAL_PP (tmp ), Z_STRLEN_PP (tmp ), PHP_INI_USER , PHP_INI_STAGE_RUNTIME , 0 TSRMLS_CC );
1903
+ zend_alter_ini_entry_ex ((char * )PHONGO_DEBUG_INI , sizeof (PHONGO_DEBUG_INI ), Z_STRVAL_PP (zdebug ), Z_STRLEN_PP (zdebug ), PHP_INI_USER , PHP_INI_STAGE_RUNTIME , 0 TSRMLS_CC );
1873
1904
}
1874
1905
#endif
1875
1906
1876
1907
#if PHP_VERSION_ID >= 70000
1877
- if (driverOptions && (tmp = zend_hash_str_find (Z_ARRVAL_P (driverOptions ), "context" , sizeof ("context" )- 1 )) != NULL ) {
1878
- ctx = php_stream_context_from_zval (tmp , 0 );
1908
+ if (driverOptions && (zcontext = zend_hash_str_find (Z_ARRVAL_P (driverOptions ), "context" , sizeof ("context" )- 1 )) != NULL ) {
1909
+ ctx = php_stream_context_from_zval (zcontext , 0 );
1879
1910
#else
1880
- if (driverOptions && zend_hash_find (Z_ARRVAL_P (driverOptions ), "context" , strlen ("context" ) + 1 , (void * * )& tmp ) == SUCCESS ) {
1881
- ctx = php_stream_context_from_zval (* tmp , 0 );
1911
+ if (driverOptions && zend_hash_find (Z_ARRVAL_P (driverOptions ), "context" , strlen ("context" ) + 1 , (void * * )& zcontext ) == SUCCESS ) {
1912
+ ctx = php_stream_context_from_zval (* zcontext , 0 );
1882
1913
#endif
1883
1914
} else {
1884
- GET_DEFAULT_CONTEXT ();
1915
+ zval * tmp = NULL ; /* PHP 5.x requires an lvalue */
1916
+ ctx = php_stream_context_from_zval (tmp , 0 );
1885
1917
}
1886
1918
1887
1919
if (mongoc_uri_get_ssl (uri )) {
@@ -1983,6 +2015,17 @@ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
1983
2015
return false;
1984
2016
}
1985
2017
2018
+ /* Keep a reference to driverOptions, since it may be referenced later for
2019
+ * lazy stream initialization. */
2020
+ if (driverOptions ) {
2021
+ #if PHP_VERSION_ID >= 70000
2022
+ ZVAL_COPY (& manager -> driverOptions , driverOptions );
2023
+ #else
2024
+ Z_ADDREF_P (driverOptions );
2025
+ manager -> driverOptions = driverOptions ;
2026
+ #endif
2027
+ }
2028
+
1986
2029
return true;
1987
2030
} /* }}} */
1988
2031
0 commit comments