diff --git a/ext/mvc/model/validator/email.c b/ext/mvc/model/validator/email.c index 0c60a1d263a..f1a381e9088 100644 --- a/ext/mvc/model/validator/email.c +++ b/ext/mvc/model/validator/email.c @@ -87,7 +87,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Email){ */ PHP_METHOD(Phalcon_Mvc_Model_Validator_Email, validate){ - zval *record, *option = NULL, *field_name = NULL, *regs, *invalid = NULL; + zval *record, *option = NULL, *field_name = NULL, *allow_empty = NULL, *regs, *invalid = NULL; zval *value = NULL, *pattern, *match_pattern, *match_zero; zval *message = NULL, *type, *is_set_code = NULL, *code = NULL; @@ -111,6 +111,20 @@ PHP_METHOD(Phalcon_Mvc_Model_Validator_Email, validate){ PHALCON_CALL_METHOD(&value, record, "readattribute", field_name); + /* + * Allow empty + */ + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "allowEmpty", 1); + + PHALCON_CALL_METHOD(&allow_empty, this_ptr, "issetoption", option); + + if (allow_empty && zend_is_true(allow_empty)) { + if (PHALCON_IS_EMPTY(value)) { + RETURN_MM_TRUE; + } + } + /** * We check if the email has a valid format using a regular expression */ diff --git a/ext/mvc/model/validator/exclusionin.c b/ext/mvc/model/validator/exclusionin.c index 1bb34b00352..0760cfee6ea 100644 --- a/ext/mvc/model/validator/exclusionin.c +++ b/ext/mvc/model/validator/exclusionin.c @@ -87,7 +87,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Exclusionin){ */ PHP_METHOD(Phalcon_Mvc_Model_Validator_Exclusionin, validate){ - zval *record, *option = NULL, *field_name = NULL, *is_set = NULL, *domain = NULL; + zval *record, *option = NULL, *field_name = NULL, *allow_empty = NULL, *is_set = NULL, *domain = NULL; zval *value = NULL, *message = NULL, *joined_domain, *type, *is_set_code = NULL, *code = NULL; PHALCON_MM_GROW(); @@ -126,6 +126,20 @@ PHP_METHOD(Phalcon_Mvc_Model_Validator_Exclusionin, validate){ PHALCON_CALL_METHOD(&value, record, "readattribute", field_name); + /* + * Allow empty + */ + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "allowEmpty", 1); + + PHALCON_CALL_METHOD(&allow_empty, this_ptr, "issetoption", option); + + if (allow_empty && zend_is_true(allow_empty)) { + if (PHALCON_IS_EMPTY(value)) { + RETURN_MM_TRUE; + } + } + /** * We check if the value contained in the array using "in_array" from the PHP * userland diff --git a/ext/mvc/model/validator/inclusionin.c b/ext/mvc/model/validator/inclusionin.c index a3b52720388..4457a23b7bc 100644 --- a/ext/mvc/model/validator/inclusionin.c +++ b/ext/mvc/model/validator/inclusionin.c @@ -87,7 +87,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Inclusionin){ */ PHP_METHOD(Phalcon_Mvc_Model_Validator_Inclusionin, validate){ - zval *record, *field = NULL, *field_name = NULL, *is_set = NULL, *domain = NULL; + zval *record, *field = NULL, *field_name = NULL, *allow_empty = NULL, *is_set = NULL, *domain = NULL; zval *value = NULL, *option, *message = NULL, *joined_domain, *is_set_code = NULL, *code = NULL; zval *type; @@ -127,6 +127,20 @@ PHP_METHOD(Phalcon_Mvc_Model_Validator_Inclusionin, validate){ PHALCON_CALL_METHOD(&value, record, "readattribute", field_name); + /* + * Allow empty + */ + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "allowEmpty", 1); + + PHALCON_CALL_METHOD(&allow_empty, this_ptr, "issetoption", option); + + if (allow_empty && zend_is_true(allow_empty)) { + if (PHALCON_IS_EMPTY(value)) { + RETURN_MM_TRUE; + } + } + /** * Check if the value is contained in the array */ diff --git a/ext/mvc/model/validator/numericality.c b/ext/mvc/model/validator/numericality.c index c388cf3a6be..f5d4b4ec0f2 100644 --- a/ext/mvc/model/validator/numericality.c +++ b/ext/mvc/model/validator/numericality.c @@ -85,7 +85,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Numericality){ */ PHP_METHOD(Phalcon_Mvc_Model_Validator_Numericality, validate){ - zval *record, *option = NULL, *field = NULL, *value = NULL, *message = NULL; + zval *record, *option = NULL, *field = NULL, *allow_empty = NULL, *value = NULL, *message = NULL; zval *type, *is_set_code = NULL, *code = NULL; PHALCON_MM_GROW(); @@ -103,6 +103,20 @@ PHP_METHOD(Phalcon_Mvc_Model_Validator_Numericality, validate){ PHALCON_CALL_METHOD(&value, record, "readattribute", field); + /* + * Allow empty + */ + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "allowEmpty", 1); + + PHALCON_CALL_METHOD(&allow_empty, this_ptr, "issetoption", option); + + if (allow_empty && zend_is_true(allow_empty)) { + if (PHALCON_IS_EMPTY(value)) { + RETURN_MM_TRUE; + } + } + /** * Check if the value is numeric using is_numeric in the PHP userland */ diff --git a/ext/mvc/model/validator/regex.c b/ext/mvc/model/validator/regex.c index 393b5abbf2a..9cb74e5fe6c 100644 --- a/ext/mvc/model/validator/regex.c +++ b/ext/mvc/model/validator/regex.c @@ -88,7 +88,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Regex){ */ PHP_METHOD(Phalcon_Mvc_Model_Validator_Regex, validate){ - zval *record, *option = NULL, *field_name = NULL, *is_set = NULL, *value = NULL; + zval *record, *option = NULL, *field_name = NULL, *allow_empty = NULL, *is_set = NULL, *value = NULL; zval *failed = NULL, *matches, *pattern = NULL, *match_pattern; zval *match_zero, *message = NULL, *type, *is_set_code = NULL, *code = NULL; @@ -119,6 +119,20 @@ PHP_METHOD(Phalcon_Mvc_Model_Validator_Regex, validate){ PHALCON_CALL_METHOD(&value, record, "readattribute", field_name); + /* + * Allow empty + */ + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "allowEmpty", 1); + + PHALCON_CALL_METHOD(&allow_empty, this_ptr, "issetoption", option); + + if (allow_empty && zend_is_true(allow_empty)) { + if (PHALCON_IS_EMPTY(value)) { + RETURN_MM_TRUE; + } + } + PHALCON_INIT_VAR(failed); ZVAL_BOOL(failed, 0); diff --git a/ext/mvc/model/validator/stringlength.c b/ext/mvc/model/validator/stringlength.c index 10257dfdd90..0c3a07a49ed 100644 --- a/ext/mvc/model/validator/stringlength.c +++ b/ext/mvc/model/validator/stringlength.c @@ -91,7 +91,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_StringLength){ */ PHP_METHOD(Phalcon_Mvc_Model_Validator_StringLength, validate){ - zval *record, *option = NULL, *field = NULL, *is_set_min = NULL, *is_set_max = NULL; + zval *record, *option = NULL, *field = NULL, *allow_empty = NULL, *is_set_min = NULL, *is_set_max = NULL; zval *value = NULL, *length = NULL, *invalid_maximum = NULL, *invalid_minimum = NULL; zval *maximum = NULL, *message = NULL, *type = NULL, *minimum = NULL, *is_set_code = NULL, *code = NULL; @@ -128,6 +128,20 @@ PHP_METHOD(Phalcon_Mvc_Model_Validator_StringLength, validate){ } PHALCON_CALL_METHOD(&value, record, "readattribute", field); + + /* + * Allow empty + */ + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "allowEmpty", 1); + + PHALCON_CALL_METHOD(&allow_empty, this_ptr, "issetoption", option); + + if (allow_empty && zend_is_true(allow_empty)) { + if (PHALCON_IS_EMPTY(value)) { + RETURN_MM_TRUE; + } + } /** * Check if mbstring is available to calculate the correct length diff --git a/ext/mvc/model/validator/url.c b/ext/mvc/model/validator/url.c index a089df8bc1d..5e8533817b9 100644 --- a/ext/mvc/model/validator/url.c +++ b/ext/mvc/model/validator/url.c @@ -84,7 +84,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Url){ */ PHP_METHOD(Phalcon_Mvc_Model_Validator_Url, validate){ - zval *record, *option = NULL, *field = NULL, *value = NULL, *flag, *is_valid = NULL; + zval *record, *option = NULL, *field = NULL, *allow_empty = NULL, *value = NULL, *flag, *is_valid = NULL; zval *message = NULL, *type, *is_set_code = NULL, *code; PHALCON_MM_GROW(); @@ -102,6 +102,20 @@ PHP_METHOD(Phalcon_Mvc_Model_Validator_Url, validate){ PHALCON_CALL_METHOD(&value, record, "readattribute", field); + /* + * Allow empty + */ + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "allowEmpty", 1); + + PHALCON_CALL_METHOD(&allow_empty, this_ptr, "issetoption", option); + + if (allow_empty && zend_is_true(allow_empty)) { + if (PHALCON_IS_EMPTY(value)) { + RETURN_MM_TRUE; + } + } + PHALCON_INIT_VAR(flag); ZVAL_LONG(flag, 273);