@@ -74,13 +74,20 @@ PHP_METHOD(WriteConcern, __construct)
74
74
intern -> write_concern = mongoc_write_concern_new ();
75
75
76
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
+ }
77
81
mongoc_write_concern_set_w (intern -> write_concern , Z_LVAL_P (w ));
78
82
} else if (Z_TYPE_P (w ) == IS_STRING ) {
79
83
if (strcmp (Z_STRVAL_P (w ), PHONGO_WRITE_CONCERN_W_MAJORITY ) == 0 ) {
80
84
mongoc_write_concern_set_w (intern -> write_concern , MONGOC_WRITE_CONCERN_W_MAJORITY );
81
85
} else {
82
86
mongoc_write_concern_set_wtag (intern -> write_concern , Z_STRVAL_P (w ));
83
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 ;
84
91
}
85
92
86
93
switch (ZEND_NUM_ARGS ()) {
@@ -91,9 +98,12 @@ PHP_METHOD(WriteConcern, __construct)
91
98
mongoc_write_concern_set_journal (intern -> write_concern , journal );
92
99
/* fallthrough */
93
100
case 2 :
94
- if (wtimeout > 0 ) {
95
- 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 ;
96
104
}
105
+
106
+ mongoc_write_concern_set_wtimeout (intern -> write_concern , wtimeout );
97
107
}
98
108
}
99
109
/* }}} */
0 commit comments