/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Url, validate){ zval *validator, *attribute, *value = NULL, *allow_empty, *valid = NULL, *label; zval *pairs, *message_str, *code, *prepared = NULL, *message; zend_class_entry *ce = Z_OBJCE_P(getThis()); PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 1); PHALCON_CALL_METHOD(&value, validator, "getvalue", attribute); PHALCON_OBS_VAR(allow_empty); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &allow_empty, getThis(), ISV(allowEmpty))); if (zend_is_true(allow_empty) && phalcon_validation_validator_isempty_helper(value)) { RETURN_MM_TRUE; } PHALCON_CALL_SELF(&valid, "valid", value); if (PHALCON_IS_FALSE(valid)) { PHALCON_OBS_VAR(label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &label, getThis(), ISV(label))); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } PHALCON_ALLOC_INIT_ZVAL(pairs); array_init_size(pairs, 1); Z_TRY_ADDREF_P(label); add_assoc_zval_ex(pairs, SL(":field"), label); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), ISV(message))); if (!zend_is_true(message_str)) { PHALCON_OBSERVE_OR_NULLIFY_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(Z_OBJCE_P(validator), message_str, validator, "Url")); } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), ISV(code))); if (Z_TYPE_P(code) == IS_NULL) { ZVAL_LONG(code, 0); } PHALCON_CALL_FUNCTION(&prepared, "strtr", message_str, pairs); message = phalcon_validation_message_construct_helper(prepared, attribute, "Url", code); Z_TRY_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/* Custom Object Destruction - calls g_source_destroy() */ void glib_source_free_obj(zend_object *object) { glib_source_object *intern = glib_source_fetch_object(object); if(!intern) { return; } GSource *source = (GSource *)intern->source; /* this will make finalize call, we MUST do this before freeing the source zval */ if(intern->source != NULL) { g_source_destroy(source); g_source_unref(source); if(intern->is_php_source) { GPhpSource *psource = (GPhpSource *)intern->source; if(!Z_ISNULL(psource->source_zval) && !Z_ISUNDEF(psource->source_zval)) { Z_TRY_DELREF_P(&psource->source_zval); ZVAL_UNDEF(&psource->source_zval); } } } zend_object_std_dtor(&intern->std); }
/* {{{ php_autoglobal_merge */ static void php_autoglobal_merge(HashTable *dest, HashTable *src) { zval *src_entry, *dest_entry; zend_string *string_key; zend_ulong num_key; int globals_check = (dest == (&EG(symbol_table))); ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { if (Z_TYPE_P(src_entry) != IS_ARRAY || (string_key && (dest_entry = zend_hash_find(dest, string_key)) == NULL) || (string_key == NULL && (dest_entry = zend_hash_index_find(dest, num_key)) == NULL) || Z_TYPE_P(dest_entry) != IS_ARRAY) { Z_TRY_ADDREF_P(src_entry); if (string_key) { if (!globals_check || ZSTR_LEN(string_key) != sizeof("GLOBALS") - 1 || memcmp(ZSTR_VAL(string_key), "GLOBALS", sizeof("GLOBALS") - 1)) { zend_hash_update(dest, string_key, src_entry); } else { Z_TRY_DELREF_P(src_entry); } } else { zend_hash_index_update(dest, num_key, src_entry); } } else { SEPARATE_ARRAY(dest_entry); php_autoglobal_merge(Z_ARRVAL_P(dest_entry), Z_ARRVAL_P(src_entry)); } } ZEND_HASH_FOREACH_END(); }
static inline void ast_update_property(zval *object, zend_string *name, zval *value, void **cache_slot) { zval name_zv; ZVAL_STR(&name_zv, name); Z_TRY_DELREF_P(value); Z_OBJ_HT_P(object)->write_property(object, &name_zv, value, cache_slot); }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_InclusionIn, validate){ zval *validator, *attribute, *value = NULL, *allow_empty, *valid = NULL; zval *label, *domain, *joined_domain, *pairs, *message_str, *message, *code; zval *prepared = NULL; zend_class_entry *ce = Z_OBJCE_P(getThis()); PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 1); PHALCON_CALL_METHOD(&value, validator, "getvalue", attribute); PHALCON_OBS_VAR(allow_empty); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &allow_empty, getThis(), ISV(allowEmpty))); if (zend_is_true(allow_empty) && phalcon_validation_validator_isempty_helper(value)) { RETURN_MM_TRUE; } /* A domain is an array with a list of valid values */ PHALCON_OBS_VAR(domain); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &domain, getThis(), ISV(domain))); if (Z_TYPE_P(domain) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Option 'domain' must be an array"); return; } PHALCON_CALL_SELF(&valid, "valid", value, domain); if (PHALCON_IS_FALSE(valid)) { PHALCON_OBS_VAR(label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &label, getThis(), ISV(label))); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } PHALCON_ALLOC_INIT_ZVAL(joined_domain); phalcon_fast_join_str(joined_domain, SL(", "), domain); PHALCON_ALLOC_INIT_ZVAL(pairs); array_init_size(pairs, 2); Z_TRY_ADDREF_P(label); add_assoc_zval_ex(pairs, SL(":field"), label); add_assoc_zval_ex(pairs, SL(":domain"), joined_domain); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), ISV(message))); if (!zend_is_true(message_str)) { PHALCON_OBSERVE_OR_NULLIFY_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(Z_OBJCE_P(validator), message_str, validator, "InclusionIn")); } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), ISV(code))); if (Z_TYPE_P(code) == IS_NULL) { ZVAL_LONG(code, 0); } PHALCON_CALL_FUNCTION(&prepared, "strtr", message_str, pairs); message = phalcon_validation_message_construct_helper(prepared, attribute, "InclusionIn", code); Z_TRY_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }