@@ -65,6 +65,35 @@ static inline bool php_phongo_bulkwrite_update_has_operators(bson_t *bupdate) /*
6565 return false;
6666} /* }}} */
6767
68+ /* Appends a document field for the given opts document and key. Returns true on
69+ * success; otherwise, false is returned and an exception is thrown. */
70+ static bool php_phongo_bulkwrite_opts_append_document (bson_t * opts , const char * opts_key , zval * zarr , const char * zarr_key TSRMLS_DC )
71+ {
72+ zval * value = php_array_fetch (zarr , zarr_key );
73+ bson_t b = BSON_INITIALIZER ;
74+
75+ if (Z_TYPE_P (value ) != IS_OBJECT && Z_TYPE_P (value ) != IS_ARRAY ) {
76+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected \"%s\" option to be array or object, %s given" , zarr_key , zend_get_type_by_const (Z_TYPE_P (value )));
77+ return false;
78+ }
79+
80+ phongo_zval_to_bson (value , PHONGO_BSON_NONE , & b , NULL TSRMLS_CC );
81+
82+ if (EG (exception )) {
83+ bson_destroy (& b );
84+ return false;
85+ }
86+
87+ if (!BSON_APPEND_DOCUMENT (opts , opts_key , & b )) {
88+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Error appending \"%s\" option" , opts_key );
89+ bson_destroy (& b );
90+ return false;
91+ }
92+
93+ bson_destroy (& b );
94+ return true;
95+ }
96+
6897#define PHONGO_BULKWRITE_APPEND_BOOL (opt , value ) \
6998 if (!BSON_APPEND_BOOL(boptions, (opt), (value))) { \
7099 phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
@@ -77,6 +106,13 @@ static inline bool php_phongo_bulkwrite_update_has_operators(bson_t *bupdate) /*
77106 return false; \
78107 }
79108
109+ #define PHONGO_BULKWRITE_OPT_DOCUMENT (opt ) \
110+ if (zoptions && php_array_existsc(zoptions, (opt))) { \
111+ if (!php_phongo_bulkwrite_opts_append_document(boptions, (opt), zoptions, (opt) TSRMLS_CC)) { \
112+ return false; \
113+ } \
114+ }
115+
80116/* Applies options (including defaults) for an update operation. */
81117static bool php_phongo_bulkwrite_update_apply_options (bson_t * boptions , zval * zoptions TSRMLS_DC )/* {{{ */
82118{
@@ -93,6 +129,7 @@ static bool php_phongo_bulkwrite_update_apply_options(bson_t *boptions, zval *zo
93129
94130 PHONGO_BULKWRITE_APPEND_BOOL ("multi" , multi );
95131 PHONGO_BULKWRITE_APPEND_BOOL ("upsert" , upsert );
132+ PHONGO_BULKWRITE_OPT_DOCUMENT ("collation" );
96133
97134 return true;
98135} /* }}} */
@@ -109,6 +146,7 @@ static bool php_phongo_bulkwrite_delete_apply_options(bson_t *boptions, zval *zo
109146 }
110147
111148 PHONGO_BULKWRITE_APPEND_INT32 ("limit" , limit );
149+ PHONGO_BULKWRITE_OPT_DOCUMENT ("collation" );
112150
113151 return true;
114152} /* }}} */
0 commit comments