@@ -179,17 +179,102 @@ static PHP_METHOD(WriteConcern, isDefault)
179179 RETURN_BOOL (mongoc_write_concern_is_default (intern -> write_concern ));
180180} /* }}} */
181181
182+ static HashTable * php_phongo_write_concern_get_properties_hash (zval * object , bool is_debug TSRMLS_DC ) /* {{{ */
183+ {
184+ php_phongo_writeconcern_t * intern ;
185+ HashTable * props ;
186+ const char * wtag ;
187+ int32_t w ;
188+ int32_t wtimeout ;
189+
190+ intern = Z_WRITECONCERN_OBJ_P (object );
191+
192+ PHONGO_GET_PROPERTY_HASH_INIT_PROPS (is_debug , intern , props , 4 );
193+
194+ if (!intern -> write_concern ) {
195+ return props ;
196+ }
197+
198+ wtag = mongoc_write_concern_get_wtag (intern -> write_concern );
199+ w = mongoc_write_concern_get_w (intern -> write_concern );
200+ wtimeout = mongoc_write_concern_get_wtimeout (intern -> write_concern );
201+
202+ #if PHP_VERSION_ID >= 70000
203+ {
204+ zval z_w ;
205+
206+ if (wtag ) {
207+ ZVAL_STRING (& z_w , wtag );
208+ zend_hash_str_update (props , "w" , sizeof ("w" ) - 1 , & z_w );
209+ } else if (mongoc_write_concern_get_wmajority (intern -> write_concern )) {
210+ ZVAL_STRING (& z_w , PHONGO_WRITE_CONCERN_W_MAJORITY );
211+ zend_hash_str_update (props , "w" , sizeof ("w" ) - 1 , & z_w );
212+ } else if (w != MONGOC_WRITE_CONCERN_W_DEFAULT ) {
213+ ZVAL_LONG (& z_w , w );
214+ zend_hash_str_update (props , "w" , sizeof ("w" ) - 1 , & z_w );
215+ }
216+
217+ if (mongoc_write_concern_journal_is_set (intern -> write_concern )) {
218+ zval z_j ;
219+
220+ ZVAL_BOOL (& z_j , mongoc_write_concern_get_journal (intern -> write_concern ));
221+ zend_hash_str_update (props , "j" , sizeof ("j" ) - 1 , & z_j );
222+ }
223+
224+ if (wtimeout != 0 ) {
225+ zval z_wtimeout ;
226+
227+ ZVAL_LONG (& z_wtimeout , wtimeout );
228+ zend_hash_str_update (props , "wtimeout" , sizeof ("wtimeout" ) - 1 , & z_wtimeout );
229+ }
230+ #else
231+ {
232+ zval * z_w ;
233+
234+ if (wtag ) {
235+ MAKE_STD_ZVAL (z_w );
236+ ZVAL_STRING (z_w , wtag , 1 );
237+ zend_hash_update (props , "w" , sizeof ("w" ), & z_w , sizeof (z_w ), NULL );
238+ } else if (mongoc_write_concern_get_wmajority (intern -> write_concern )) {
239+ MAKE_STD_ZVAL (z_w );
240+ ZVAL_STRING (z_w , PHONGO_WRITE_CONCERN_W_MAJORITY , 1 );
241+ zend_hash_update (props , "w" , sizeof ("w" ), & z_w , sizeof (z_w ), NULL );
242+ } else if (w != MONGOC_WRITE_CONCERN_W_DEFAULT ) {
243+ MAKE_STD_ZVAL (z_w );
244+ ZVAL_LONG (z_w , w );
245+ zend_hash_update (props , "w" , sizeof ("w" ), & z_w , sizeof (z_w ), NULL );
246+ }
247+
248+ if (mongoc_write_concern_journal_is_set (intern -> write_concern )) {
249+ zval * z_j ;
250+
251+ MAKE_STD_ZVAL (z_j );
252+ ZVAL_BOOL (z_j , mongoc_write_concern_get_journal (intern -> write_concern ));
253+ zend_hash_update (props , "j" , sizeof ("j" ), & z_j , sizeof (z_j ), NULL );
254+ }
255+
256+ if (wtimeout != 0 ) {
257+ zval * z_wtimeout ;
258+
259+ MAKE_STD_ZVAL (z_wtimeout );
260+ ZVAL_LONG (z_wtimeout , wtimeout );
261+ zend_hash_update (props , "wtimeout" , sizeof ("wtimeout" ), & z_wtimeout , sizeof (z_wtimeout ), NULL );
262+ }
263+ #endif
264+ }
265+
266+ return props ;
267+ } /* }}} */
268+
182269/* {{{ proto array MongoDB\Driver\WriteConcern::bsonSerialize()
183270*/
184271static PHP_METHOD (WriteConcern , bsonSerialize )
185272{
186- const mongoc_write_concern_t * write_concern = phongo_write_concern_from_zval (getThis () TSRMLS_CC );
187-
188273 if (zend_parse_parameters_none () == FAILURE ) {
189274 return ;
190275 }
191276
192- php_phongo_write_concern_to_zval (return_value , write_concern );
277+ ZVAL_ARR (return_value , php_phongo_write_concern_get_properties_hash ( getThis (), true TSRMLS_CC ) );
193278 convert_to_object (return_value );
194279} /* }}} */
195280
@@ -225,6 +310,11 @@ static void php_phongo_writeconcern_free_object(phongo_free_object_arg* object T
225310
226311 zend_object_std_dtor (& intern -> std TSRMLS_CC );
227312
313+ if (intern -> properties ) {
314+ zend_hash_destroy (intern -> properties );
315+ FREE_HASHTABLE (intern -> properties );
316+ }
317+
228318 if (intern -> write_concern ) {
229319 mongoc_write_concern_destroy (intern -> write_concern );
230320 }
@@ -260,15 +350,14 @@ static phongo_create_object_retval php_phongo_writeconcern_create_object(zend_cl
260350
261351static HashTable * php_phongo_writeconcern_get_debug_info (zval * object , int * is_temp TSRMLS_DC ) /* {{{ */
262352{
263- zval retval = ZVAL_STATIC_INIT ;
264- const mongoc_write_concern_t * write_concern = phongo_write_concern_from_zval (object TSRMLS_CC );
265-
266353 * is_temp = 1 ;
267- php_phongo_write_concern_to_zval (& retval , write_concern );
354+ return php_phongo_write_concern_get_properties_hash (object , true TSRMLS_CC );
355+ } /* }}} */
268356
269- return Z_ARRVAL (retval );
357+ static HashTable * php_phongo_writeconcern_get_properties (zval * object TSRMLS_DC ) /* {{{ */
358+ {
359+ return php_phongo_write_concern_get_properties_hash (object , false TSRMLS_CC );
270360} /* }}} */
271- /* }}} */
272361
273362void php_phongo_writeconcern_init_ce (INIT_FUNC_ARGS ) /* {{{ */
274363{
@@ -284,6 +373,7 @@ void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) /* {{{ */
284373
285374 memcpy (& php_phongo_handler_writeconcern , phongo_get_std_object_handlers (), sizeof (zend_object_handlers ));
286375 php_phongo_handler_writeconcern .get_debug_info = php_phongo_writeconcern_get_debug_info ;
376+ php_phongo_handler_writeconcern .get_properties = php_phongo_writeconcern_get_properties ;
287377#if PHP_VERSION_ID >= 70000
288378 php_phongo_handler_writeconcern .free_obj = php_phongo_writeconcern_free_object ;
289379 php_phongo_handler_writeconcern .offset = XtOffsetOf (php_phongo_writeconcern_t , std );
0 commit comments