44
44
45
45
PHONGO_API zend_class_entry * php_phongo_writeconcern_ce ;
46
46
47
+ zend_object_handlers php_phongo_handler_writeconcern ;
48
+
47
49
#define PHONGO_WRITE_CONCERN_W_MAJORITY "majority"
48
50
49
51
/* {{{ proto MongoDB\Driver\WriteConcern WriteConcern::__construct(string $wstring[, integer $wtimeout[, boolean $journal[, boolean $fsync]]])
@@ -58,6 +60,7 @@ PHP_METHOD(WriteConcern, __construct)
58
60
zend_bool journal = 0 ;
59
61
zend_bool fsync = 0 ;
60
62
long w ;
63
+ (void )return_value ; (void )return_value_ptr ; (void )return_value_used ;
61
64
62
65
63
66
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
@@ -87,12 +90,12 @@ PHP_METHOD(WriteConcern, __construct)
87
90
if (fsync ) {
88
91
mongoc_write_concern_set_fsync (intern -> write_concern , true);
89
92
}
90
- // fallthrough
93
+ /* fallthrough */
91
94
case 3 :
92
95
if (journal ) {
93
96
mongoc_write_concern_set_journal (intern -> write_concern , true);
94
97
}
95
- // fallthrough
98
+ /* fallthrough */
96
99
case 2 :
97
100
if (wtimeout > 0 ) {
98
101
mongoc_write_concern_set_wtimeout (intern -> write_concern , wtimeout );
@@ -138,32 +141,61 @@ static void php_phongo_writeconcern_free_object(void *object TSRMLS_DC) /* {{{ *
138
141
zend_object_value php_phongo_writeconcern_create_object (zend_class_entry * class_type TSRMLS_DC ) /* {{{ */
139
142
{
140
143
zend_object_value retval ;
141
- php_phongo_writeconcern_t * intern ;
144
+ php_phongo_writeconcern_t * intern = NULL ;
142
145
143
- intern = (php_phongo_writeconcern_t * )emalloc (sizeof (php_phongo_writeconcern_t ));
144
- memset (intern , 0 , sizeof (php_phongo_writeconcern_t ));
146
+ intern = (php_phongo_writeconcern_t * )ecalloc (1 , sizeof * intern );
145
147
146
148
zend_object_std_init (& intern -> std , class_type TSRMLS_CC );
147
149
object_properties_init (& intern -> std , class_type );
148
150
149
151
retval .handle = zend_objects_store_put (intern , (zend_objects_store_dtor_t ) zend_objects_destroy_object , php_phongo_writeconcern_free_object , NULL TSRMLS_CC );
150
- retval .handlers = phongo_get_std_object_handlers () ;
152
+ retval .handlers = & php_phongo_handler_writeconcern ;
151
153
152
154
return retval ;
153
155
} /* }}} */
156
+
157
+ HashTable * php_phongo_writeconcern_get_debug_info (zval * object , int * is_temp TSRMLS_DC ) /* {{{ */
158
+ {
159
+ zval retval = zval_used_for_init ;
160
+ mongoc_write_concern_t * write_concern = phongo_write_concern_from_zval (object TSRMLS_CC );
161
+ char * wtag ;
162
+
163
+
164
+ * is_temp = 1 ;
165
+ array_init (& retval );
166
+
167
+ wtag = (char * )mongoc_write_concern_get_wtag (write_concern );
168
+ if (wtag ) {
169
+ add_assoc_string_ex (& retval , ZEND_STRS ("w" ), wtag , 1 );
170
+ } else {
171
+ if (!mongoc_write_concern_get_wmajority (write_concern )) {
172
+ add_assoc_long_ex (& retval , ZEND_STRS ("w" ), mongoc_write_concern_get_w (write_concern ));
173
+ }
174
+ }
175
+ add_assoc_bool_ex (& retval , ZEND_STRS ("wmajority" ), mongoc_write_concern_get_wmajority (write_concern ));
176
+ add_assoc_long_ex (& retval , ZEND_STRS ("wtimeout" ), mongoc_write_concern_get_wtimeout (write_concern ));
177
+ add_assoc_bool_ex (& retval , ZEND_STRS ("fsync" ), mongoc_write_concern_get_fsync (write_concern ));
178
+ add_assoc_bool_ex (& retval , ZEND_STRS ("journal" ), mongoc_write_concern_get_journal (write_concern ));
179
+
180
+
181
+ return Z_ARRVAL (retval );
182
+ } /* }}} */
154
183
/* }}} */
155
184
156
185
/* {{{ PHP_MINIT_FUNCTION */
157
186
PHP_MINIT_FUNCTION (WriteConcern )
158
187
{
159
- (void )type ; /* We don't care if we are loaded via dl() or extension= */
188
+ (void )type ; ( void ) module_number ;
160
189
zend_class_entry ce ;
161
190
162
191
INIT_NS_CLASS_ENTRY (ce , "MongoDB\\Driver" , "WriteConcern" , php_phongo_writeconcern_me );
163
- ce .create_object = php_phongo_writeconcern_create_object ;
164
192
php_phongo_writeconcern_ce = zend_register_internal_class (& ce TSRMLS_CC );
193
+ php_phongo_writeconcern_ce -> create_object = php_phongo_writeconcern_create_object ;
165
194
php_phongo_writeconcern_ce -> ce_flags |= ZEND_ACC_FINAL_CLASS ;
166
195
196
+ memcpy (& php_phongo_handler_writeconcern , phongo_get_std_object_handlers (), sizeof (zend_object_handlers ));
197
+ php_phongo_handler_writeconcern .get_debug_info = php_phongo_writeconcern_get_debug_info ;
198
+
167
199
zend_declare_class_constant_stringl (php_phongo_writeconcern_ce , ZEND_STRL ("MAJORITY" ), ZEND_STRL (PHONGO_WRITE_CONCERN_W_MAJORITY ) TSRMLS_CC );
168
200
169
201
return SUCCESS ;
0 commit comments