@@ -53,19 +53,18 @@ PHP_METHOD(WriteConcern, __construct)
53
53
{
54
54
php_phongo_writeconcern_t * intern ;
55
55
zend_error_handling error_handling ;
56
- char * wstring ;
57
- int wstring_len ;
56
+ zval * w ;
58
57
long wtimeout = 0 ;
59
58
zend_bool journal = 0 ;
60
59
zend_bool fsync = 0 ;
61
- long w ;
60
+
62
61
(void )return_value ; (void )return_value_ptr ; (void )return_value_used ;
63
62
64
63
65
64
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
66
65
intern = (php_phongo_writeconcern_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
67
66
68
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s |lbb" , & wstring , & wstring_len , & wtimeout , & journal , & fsync ) == FAILURE ) {
67
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "z |lbb" , & w , & wtimeout , & journal , & fsync ) == FAILURE ) {
69
68
zend_restore_error_handling (& error_handling TSRMLS_CC );
70
69
return ;
71
70
}
@@ -74,14 +73,21 @@ PHP_METHOD(WriteConcern, __construct)
74
73
75
74
intern -> write_concern = mongoc_write_concern_new ();
76
75
77
- if (IS_LONG == is_numeric_string (wstring , wstring_len , & w , NULL , 0 )) {
78
- mongoc_write_concern_set_w (intern -> write_concern , w );
79
- } else {
80
- if (strcmp (wstring , PHONGO_WRITE_CONCERN_W_MAJORITY ) == 0 ) {
76
+ if (Z_TYPE_P (w ) == IS_LONG ) {
77
+ if (Z_LVAL_P (w ) < -3 ) {
78
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected w to be >= -3, %ld given" , Z_LVAL_P (w ));
79
+ return ;
80
+ }
81
+ mongoc_write_concern_set_w (intern -> write_concern , Z_LVAL_P (w ));
82
+ } else if (Z_TYPE_P (w ) == IS_STRING ) {
83
+ if (strcmp (Z_STRVAL_P (w ), PHONGO_WRITE_CONCERN_W_MAJORITY ) == 0 ) {
81
84
mongoc_write_concern_set_w (intern -> write_concern , MONGOC_WRITE_CONCERN_W_MAJORITY );
82
85
} else {
83
- mongoc_write_concern_set_wtag (intern -> write_concern , wstring );
86
+ mongoc_write_concern_set_wtag (intern -> write_concern , Z_STRVAL_P ( w ) );
84
87
}
88
+ } else {
89
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected w to be integer or string, %s given" , zend_get_type_by_const (Z_TYPE_P (w )));
90
+ return ;
85
91
}
86
92
87
93
switch (ZEND_NUM_ARGS ()) {
@@ -92,9 +98,12 @@ PHP_METHOD(WriteConcern, __construct)
92
98
mongoc_write_concern_set_journal (intern -> write_concern , journal );
93
99
/* fallthrough */
94
100
case 2 :
95
- if (wtimeout > 0 ) {
96
- mongoc_write_concern_set_wtimeout (intern -> write_concern , wtimeout );
101
+ if (wtimeout < 0 ) {
102
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected wtimeout to be >= 0, %ld given" , wtimeout );
103
+ return ;
97
104
}
105
+
106
+ mongoc_write_concern_set_wtimeout (intern -> write_concern , wtimeout );
98
107
}
99
108
}
100
109
/* }}} */
0 commit comments