/** * 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; }
/** * Sets the group associated with the route * * @param Phalcon\Mvc\Router\Group $group * @return Phalcon\Mvc\RouteInterface */ PHP_METHOD(Phalcon_Mvc_Router_Route, setGroup) { zval *group; phalcon_fetch_params(0, 1, 0, &group); PHALCON_VERIFY_CLASS_EX(group, phalcon_mvc_router_group_ce, phalcon_mvc_router_exception_ce, 0); phalcon_update_property_this(getThis(), SL("_group"), group TSRMLS_CC); RETURN_THISW(); }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Between, validate){ zval *validator, *attribute, value = {}, allow_empty = {}, minimum = {}, maximum = {}, label = {}, pairs = {}, valid = {}, message_str = {}, code = {}, prepared = {}, message = {}; zend_class_entry *ce = Z_OBJCE_P(getThis()); phalcon_fetch_params(0, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 0); PHALCON_CALL_METHODW(&value, validator, "getvalue", attribute); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&allow_empty, ce, getThis(), ISV(allowEmpty))); if (zend_is_true(&allow_empty) && phalcon_validation_validator_isempty_helper(&value)) { RETURN_TRUE; } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minimum, ce, getThis(), "minimum")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maximum, ce, getThis(), "maximum")); PHALCON_CALL_SELFW(&valid, "valid", &value, &minimum, &maximum); if (PHALCON_IS_FALSE(&valid)) { RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&label, ce, getThis(), ISV(label))); if (!zend_is_true(&label)) { PHALCON_CALL_METHODW(&label, validator, "getlabel", attribute); if (!zend_is_true(&label)) { PHALCON_CPY_WRT_CTOR(&label, attribute); } } array_init_size(&pairs, 3); phalcon_array_update_str(&pairs, SL(":field"), &label, PH_COPY); phalcon_array_update_str(&pairs, SL(":min"), &minimum, PH_COPY); phalcon_array_update_str(&pairs, SL(":max"), &maximum, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "Between")); } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&code, ce, getThis(), ISV(code))); if (Z_TYPE_P(&code) == IS_NULL) { ZVAL_LONG(&code, 0); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "Between", &code); PHALCON_CALL_METHODW(NULL, validator, "appendmessage", &message); RETURN_FALSE; } RETURN_TRUE; }
/** * Registers a form in the Forms Manager * * @param string $name * @param Phalcon\Forms\Form $form * @return Phalcon\Forms\Manager */ PHP_METHOD(Phalcon_Forms_Manager, set){ zval *name, *form; phalcon_fetch_params(0, 2, 0, &name, &form); PHALCON_ENSURE_IS_STRING(name); PHALCON_VERIFY_CLASS_EX(form, phalcon_forms_form_ce, phalcon_forms_exception_ce, 0); phalcon_update_property_array(getThis(), SL("_forms"), name, form); RETURN_THISW(); }
/** * Registers a form in the Forms Manager * * @param string $name * @param Phalcon\Forms\Form $form * @return Phalcon\Forms\Manager */ PHP_METHOD(Phalcon_Forms_Manager, set){ zval **name, **form; phalcon_fetch_params_ex(2, 0, &name, &form); PHALCON_ENSURE_IS_STRING(name); PHALCON_VERIFY_CLASS_EX(*form, phalcon_forms_form_ce, phalcon_forms_exception_ce, 0); phalcon_update_property_array(this_ptr, SL("_forms"), *name, *form TSRMLS_CC); RETURN_THISW(); }
/** * Phalcon\Queue\Beanstalk\Job * * @param Phalcon\Queue\Beanstalk $queue * @param string $id * @param mixed $body */ PHP_METHOD(Phalcon_Queue_Beanstalk_Job, __construct){ zval **queue, **id, **body; phalcon_fetch_params_ex(3, 0, &queue, &id, &body); PHALCON_VERIFY_CLASS_EX(*queue, phalcon_queue_beanstalk_ce, phalcon_exception_ce, 0); PHALCON_ENSURE_IS_STRING(id); phalcon_update_property_this(this_ptr, SL("_queue"), *queue TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_id"), *id TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_body"), *body TSRMLS_CC); }
/** * Phalcon\Queue\Beanstalk\Job * * @param Phalcon\Queue\Beanstalk $queue * @param string $id * @param mixed $body */ PHP_METHOD(Phalcon_Queue_Beanstalk_Job, __construct){ zval *queue, *id, *body; phalcon_fetch_params(0, 3, 0, &queue, &id, &body); PHALCON_VERIFY_CLASS_EX(queue, phalcon_queue_beanstalk_ce, phalcon_exception_ce, 0); PHALCON_ENSURE_IS_STRING(id); phalcon_update_property_this(getThis(), SL("_queue"), queue); phalcon_update_property_this(getThis(), SL("_id"), id ); phalcon_update_property_this(getThis(), SL("_body"), body ); }
/** * Adds a raw resource to the manager * *<code> * $assets->addResource(new Phalcon\Assets\Resource('css', 'css/style.css')); *</code> * * @param Phalcon\Assets\Resource $resource * @return Phalcon\Assets\Manager */ PHP_METHOD(Phalcon_Assets_Manager, addResource){ zval *resource, *type = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &resource); PHALCON_VERIFY_CLASS_EX(resource, phalcon_assets_resource_ce, phalcon_assets_exception_ce, 1); PHALCON_CALL_METHOD(&type, resource, "gettype"); /** * Adds the resource by its type */ PHALCON_CALL_METHOD(NULL, this_ptr, "addresourcebytype", type, resource); RETURN_THIS(); }
/** * Reads column-map information for certain model using a MODEL_* constant * *<code> * print_r($metaData->readColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP)); *</code> * * @param Phalcon\Mvc\ModelInterface $model * @param int $index */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, readColumnMapIndex){ zval **model, **index, *key_name, *column_map = NULL, *null_value; zval *column_map_model, *attributes; phalcon_fetch_params_ex(2, 0, &model, &index); PHALCON_VERIFY_CLASS_EX(*model, phalcon_mvc_modelinterface_ce, phalcon_mvc_model_exception_ce, 0); PHALCON_ENSURE_IS_LONG(index); PHALCON_MM_GROW(); if (!PHALCON_GLOBAL(orm).column_renaming) { RETURN_MM(); } PHALCON_INIT_VAR(key_name); phalcon_get_class(key_name, *model, 1 TSRMLS_CC); PHALCON_OBS_VAR(column_map); phalcon_read_property_this(&column_map, this_ptr, SL("_columnMap"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset(column_map, key_name)) { null_value = PHALCON_GLOBAL(z_null); PHALCON_CALL_METHOD(NULL, this_ptr, "_initialize", *model, null_value, null_value, null_value); PHALCON_OBS_NVAR(column_map); phalcon_read_property_this(&column_map, this_ptr, SL("_columnMap"), PH_NOISY TSRMLS_CC); } PHALCON_OBS_VAR(column_map_model); phalcon_array_fetch(&column_map_model, column_map, key_name, PH_NOISY); PHALCON_OBS_VAR(attributes); phalcon_array_fetch(&attributes, column_map_model, *index, PH_NOISY); RETURN_CTOR(attributes); }
/** * 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(), phalcon_interned_allowEmpty TSRMLS_CC)); 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(), phalcon_interned_domain TSRMLS_CC)); 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(), phalcon_interned_label TSRMLS_CC)); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } ALLOC_INIT_ZVAL(joined_domain); phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC); PHALCON_ALLOC_GHOST_ZVAL(pairs); array_init_size(pairs, 2); Z_ADDREF_P(label); add_assoc_zval_ex(pairs, SS(":field"), label); add_assoc_zval_ex(pairs, SS(":domain"), joined_domain); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), phalcon_interned_message TSRMLS_CC)); 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" TSRMLS_CC)); } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), phalcon_interned_code TSRMLS_CC)); 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 TSRMLS_CC); Z_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_File, validate) { zval *validator, *attribute, value = {}, allow_empty = {}, mimes = {}, minsize = {}, maxsize = {}, minwidth = {}, maxwidth = {}, minheight = {}, maxheight = {}; zval valid = {}, type = {}, code = {}, message_str = {}, message = {}, join_mimes = {}, label = {}, pairs = {}, prepared = {}; zend_class_entry *ce = Z_OBJCE_P(getThis()); phalcon_fetch_params(0, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 0); PHALCON_CALL_METHODW(&value, validator, "getvalue", attribute); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&allow_empty, ce, getThis(), ISV(allowEmpty))); if (zend_is_true(&allow_empty) && phalcon_validation_validator_isempty_helper(&value)) { RETURN_TRUE; } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&mimes, ce, getThis(), "mimes")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minsize, ce, getThis(), "minsize")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxsize, ce, getThis(), "maxsize")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minwidth, ce, getThis(), "minwidth")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxwidth, ce, getThis(), "maxwidth")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minheight, ce, getThis(), "minheight")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxheight, ce, getThis(), "maxheight")); PHALCON_CALL_SELFW(&valid, "valid", &value, &minsize, &maxsize, &mimes, &minwidth, &maxwidth, &minheight, &maxheight); if (PHALCON_IS_FALSE(&valid)) { phalcon_return_property(&type, getThis(), SL("_type")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&label, ce, getThis(), ISV(label))); if (!zend_is_true(&label)) { PHALCON_CALL_METHODW(&label, validator, "getlabel", attribute); if (!zend_is_true(&label)) { PHALCON_CPY_WRT_CTOR(&label, attribute); } } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&code, ce, getThis(), ISV(code))); if (Z_TYPE(code) == IS_NULL) { ZVAL_LONG(&code, 0); } array_init(&pairs); phalcon_array_update_str(&pairs, SL(":field"), &label, PH_COPY); if (phalcon_compare_strict_string(&type, SL("TooLarge"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMaxSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLarge", &code); } else if (phalcon_compare_strict_string(&type, SL("TooSmall"))) { phalcon_array_update_str(&pairs, SL(":min"), &minsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMinSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooSmall", &code); } else if (phalcon_compare_strict_string(&type, SL("MimeValid"))) { phalcon_fast_join_str(&join_mimes, SL(", "), &mimes); phalcon_array_update_str(&pairs, SL(":mimes"), &join_mimes, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileType")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "FileType", &code); } else if (phalcon_compare_strict_string(&type, SL("TooLarge"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMaxSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLarge", &code); } else if (phalcon_compare_strict_string(&type, SL("TooNarrow"))) { phalcon_array_update_str(&pairs, SL(":min"), &minwidth, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMinWidth")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooNarrow", &code); } else if (phalcon_compare_strict_string(&type, SL("TooWide"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxwidth, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMaxWidth")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooWide", &code); } else if (phalcon_compare_strict_string(&type, SL("TooShort"))) { phalcon_array_update_str(&pairs, SL(":min"), &minheight, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMinHeight")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooShort", &code); } else if (phalcon_compare_strict_string(&type, SL("TooLong"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxheight, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMaxHeight")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLong", &code); } else { RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileValid")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "File", &code); } PHALCON_CALL_METHODW(NULL, validator, "appendmessage", &message); RETURN_FALSE; } RETURN_TRUE; }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Confirmation, validate){ zval *validator, *attribute, *with_attribute; zval *value = NULL, *with_value = NULL, *message_str, *message, *code; zval *label, *with_label, *pairs, *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_OBS_VAR(with_attribute); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &with_attribute, getThis(), "with" TSRMLS_CC)); PHALCON_CALL_METHOD(&value, validator, "getvalue", attribute); PHALCON_CALL_METHOD(&with_value, validator, "getvalue", with_attribute); if (!PHALCON_IS_EQUAL(value, with_value)) { PHALCON_OBS_VAR(label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &label, getThis(), phalcon_interned_label TSRMLS_CC)); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } PHALCON_OBS_VAR(with_label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &with_label, getThis(), phalcon_interned_label TSRMLS_CC)); if (!zend_is_true(with_label)) { PHALCON_CALL_METHOD(&with_label, validator, "getlabel", with_attribute); if (!zend_is_true(with_label)) { PHALCON_CPY_WRT(with_label, with_attribute); } } PHALCON_ALLOC_GHOST_ZVAL(pairs); array_init_size(pairs, 2); Z_ADDREF_P(label); add_assoc_zval_ex(pairs, SS(":field"), label); Z_ADDREF_P(with_label); add_assoc_zval_ex(pairs, SS(":with"), with_label); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), phalcon_interned_message TSRMLS_CC)); 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, "Confirmation" TSRMLS_CC)); } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), phalcon_interned_code TSRMLS_CC)); 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, "Confirmation", code TSRMLS_CC); Z_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Handles uncaught exceptions * * @param \Exception $exception * @return boolean */ PHP_METHOD(Phalcon_Debug, onUncaughtException){ zval *exception, *is_active = NULL, *message = NULL; zval *class_name, *css_sources = NULL, *escaped_message = NULL; zval *html, *version = NULL, *file = NULL, *line = NULL, *show_back_trace; zval *data_vars, *trace = NULL, *trace_item = NULL, *n = NULL, *html_item = NULL; zval *_REQUEST, *value = NULL, *key_request = NULL, *joined_value = NULL, *_SERVER; zval *key_server = NULL, *files = NULL, *key_file = NULL; zval *memory, *data_var = NULL, *key_var = NULL, *variable = NULL, *dumped_argument = NULL; zval *js_sources = NULL, *formatted_file = NULL; HashTable *ah0, *ah1, *ah2, *ah3, *ah4; HashPosition hp0, hp1, hp2, hp3, hp4; zval **hd; char* link_format; zend_bool ini_exists = 1; zval z_link_format = zval_used_for_init; zend_class_entry *ce; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &exception); PHALCON_VERIFY_CLASS_EX(exception, zend_exception_get_default(TSRMLS_C), phalcon_exception_ce, 1); /** * Cancel the output buffer if active */ if (phalcon_ob_get_level(TSRMLS_C) > 0) { phalcon_ob_end_clean(TSRMLS_C); } is_active = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_isActive") TSRMLS_CC); /** * Avoid that multiple exceptions being showed */ if (zend_is_true(is_active)) { PHALCON_CALL_METHOD(&message, exception, "getmessage"); zend_print_zval(message, 0); } /** * Globally block the debug component to avoid other exceptions must be shown */ zend_update_static_property_bool(phalcon_debug_ce, SL("_isActive"), 1 TSRMLS_CC); PHALCON_INIT_VAR(class_name); ce = Z_OBJCE_P(exception); ZVAL_STRINGL(class_name, ce->name, ce->name_length, !IS_INTERNED(ce->name)); PHALCON_CALL_METHOD(&message, exception, "getmessage"); /** * CSS static sources to style the error presentation */ PHALCON_CALL_METHOD(&css_sources, this_ptr, "getcsssources"); /** * Escape the exception's message avoiding possible XSS injections? */ PHALCON_CPY_WRT(escaped_message, message); /** * Use the exception info as document's title */ PHALCON_INIT_VAR(html); PHALCON_CONCAT_SVSVS(html, "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/><title>", class_name, ": ", escaped_message, "</title>"); PHALCON_SCONCAT_VS(html, css_sources, "</head><body>"); /** * Get the version link */ PHALCON_CALL_METHOD(&version, this_ptr, "getversion"); phalcon_concat_self(&html, version TSRMLS_CC); PHALCON_CALL_METHOD(&file, exception, "getfile"); PHALCON_CALL_METHOD(&line, exception, "getline"); link_format = zend_ini_string_ex(SS("xdebug.file_link_format"), 0, &ini_exists); if (!link_format || !ini_exists || !strlen(link_format)) { link_format = "file://%f#%l"; } ZVAL_STRING(&z_link_format, link_format, 0); PHALCON_CALL_METHOD(&formatted_file, getThis(), "getfilelink", file, line, &z_link_format); /** * Main exception info */ phalcon_concat_self_str(&html, SL("<div align=\"center\"><div class=\"error-main\">") TSRMLS_CC); PHALCON_SCONCAT_SVSVS(html, "<h1>", class_name, ": ", escaped_message, "</h1>"); PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-file\">", formatted_file, " (", line, ")</span>"); phalcon_concat_self_str(&html, SL("</div>") TSRMLS_CC); PHALCON_OBS_VAR(show_back_trace); phalcon_read_property_this(&show_back_trace, this_ptr, SL("_showBackTrace"), PH_NOISY TSRMLS_CC); /** * Check if the developer wants to show the backtrace or not */ if (zend_is_true(show_back_trace)) { PHALCON_OBS_VAR(data_vars); phalcon_read_property_this(&data_vars, this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); /** * Create the tabs in the page */ phalcon_concat_self_str(&html, SL("<div class=\"error-info\"><div id=\"tabs\"><ul>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-1\">Backtrace</a></li>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-2\">Request</a></li>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-3\">Server</a></li>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-4\">Included Files</a></li>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-5\">Memory</a></li>") TSRMLS_CC); if (Z_TYPE_P(data_vars) == IS_ARRAY) { phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-6\">Variables</a></li>") TSRMLS_CC); } phalcon_concat_self_str(&html, SL("</ul>") TSRMLS_CC); /** * Print backtrace */ phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-1\"><table cellspacing=\"0\" align=\"center\" width=\"100%\">") TSRMLS_CC); PHALCON_CALL_METHOD(&trace, exception, "gettrace"); phalcon_is_iterable(trace, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(n, ah0, hp0); PHALCON_GET_HVALUE(trace_item); /** * Every line in the trace is rendered using 'showTraceItem' */ PHALCON_CALL_METHOD(&html_item, this_ptr, "showtraceitem", n, trace_item, &z_link_format); phalcon_concat_self(&html, html_item TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Print _REQUEST superglobal */ phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-2\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC); _REQUEST = phalcon_get_global(SS("_REQUEST") TSRMLS_CC); if (Z_TYPE_P(_REQUEST) == IS_ARRAY) { phalcon_is_iterable(_REQUEST, &ah1, &hp1, 0, 0); while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_HKEY(key_request, ah1, hp1); PHALCON_GET_HVALUE(value); if (Z_TYPE_P(value) == IS_ARRAY) { PHALCON_CALL_METHOD(&joined_value, this_ptr, "_getvardump", value); PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_request, "</td><td>", joined_value, "</td></tr>"); } else { PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_request, "</td><td>", value, "</td></tr>"); } zend_hash_move_forward_ex(ah1, &hp1); } } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Print _SERVER superglobal */ phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-3\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC); _SERVER = phalcon_get_global(SS("_SERVER") TSRMLS_CC); if (Z_TYPE_P(_SERVER) == IS_ARRAY) { phalcon_is_iterable(_SERVER, &ah2, &hp2, 0, 0); while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { PHALCON_GET_HKEY(key_server, ah2, hp2); PHALCON_GET_HVALUE(value); PHALCON_CALL_METHOD(&dumped_argument, this_ptr, "_getvardump", value); PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_server, "</td><td>", dumped_argument, "</td></tr>"); zend_hash_move_forward_ex(ah2, &hp2); } } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Show included files */ PHALCON_CALL_FUNCTION(&files, "get_included_files"); phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-4\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<tr><th>#</th><th>Path</th></tr>") TSRMLS_CC); phalcon_is_iterable(files, &ah3, &hp3, 0, 0); while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { PHALCON_GET_HKEY(key_file, ah3, hp3); PHALCON_GET_HVALUE(value); PHALCON_SCONCAT_SVSVS(html, "<tr><td>", key_file, "</th><td>", value, "</td></tr>"); zend_hash_move_forward_ex(ah3, &hp3); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Memory usage */ PHALCON_INIT_VAR(memory); ZVAL_LONG(memory, zend_memory_usage(1 TSRMLS_CC)); phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-5\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); PHALCON_SCONCAT_SVS(html, "<tr><th colspan=\"2\">Memory</th></tr><tr><td>Usage</td><td>", memory, "</td></tr>"); phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Print extra variables passed to the component */ if (Z_TYPE_P(data_vars) == IS_ARRAY) { phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-6\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC); phalcon_is_iterable(data_vars, &ah4, &hp4, 0, 0); while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { PHALCON_GET_HKEY(key_var, ah4, hp4); PHALCON_GET_HVALUE(data_var); PHALCON_OBS_NVAR(variable); phalcon_array_fetch_long(&variable, data_var, 0, PH_NOISY); PHALCON_CALL_METHOD(&dumped_argument, this_ptr, "_getvardump", variable); PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_var, "</td><td>", dumped_argument, "</td></tr>"); zend_hash_move_forward_ex(ah4, &hp4); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); } phalcon_concat_self_str(&html, SL("</div>") TSRMLS_CC); } /** * Get Javascript sources */ PHALCON_CALL_METHOD(&js_sources, this_ptr, "getjssources"); PHALCON_SCONCAT_VS(html, js_sources, "</div></body></html>"); /** * Print the HTML, @TODO, add an option to store the html */ zend_print_zval(html, 0); /** * Unlock the exception renderer */ zend_update_static_property_bool(phalcon_debug_ce, SL("_isActive"), 0 TSRMLS_CC); RETURN_MM_TRUE; }
/** * Rpc call * * @param string $method * @param string $data * @return Phalcon\JsonRpc\Response */ PHP_METHOD(Phalcon_JsonRpc_Client, call){ zval *method = NULL, *data = NULL, *httpclient, *id, *jsonrpc_message, *json_message = NULL, *response = NULL; zval *code = NULL, *body = NULL, *json = NULL, *jsonrpc_response, *result, *error; int i; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &method, &data); httpclient = phalcon_fetch_nproperty_this(this_ptr, SL("_httpclient"), PH_NOISY TSRMLS_CC); id = phalcon_fetch_nproperty_this(this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); i = Z_LVAL_P(id) + 1; ZVAL_LONG(id, i); phalcon_update_property_this(this_ptr, SL("_id"), id TSRMLS_CC); PHALCON_INIT_VAR(jsonrpc_message); array_init(jsonrpc_message); phalcon_array_update_string_string(&jsonrpc_message, SL("jsonrpc"), SL("2.0"), 0); phalcon_array_update_string(&jsonrpc_message, SL("method"), method, PH_COPY); if (data) { phalcon_array_update_string(&jsonrpc_message, SL("params"), data, PH_COPY); } phalcon_array_update_string(&jsonrpc_message, SL("id"), id, PH_COPY); PHALCON_CALL_FUNCTION(&json_message, "json_encode", jsonrpc_message); PHALCON_CALL_METHOD(NULL, httpclient, "setdata", json_message); PHALCON_CALL_METHOD(&response, httpclient, "post"); PHALCON_VERIFY_CLASS_EX(response, phalcon_http_client_response_ce, phalcon_jsonrpc_client_exception_ce, 1); PHALCON_CALL_METHOD(&code, response, "getstatuscode"); PHALCON_CALL_METHOD(&body, response, "getbody"); PHALCON_INIT_VAR(jsonrpc_response); object_init_ex(jsonrpc_response, phalcon_jsonrpc_client_response_ce); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "__construct", body); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "setcode", code); if (PHALCON_IS_NOT_EMPTY(body)) { PHALCON_CALL_FUNCTION(&json, "json_decode", body, PHALCON_GLOBAL(z_true)); if (Z_TYPE_P(json) == IS_ARRAY) { if (phalcon_array_isset_string(json, SS("id"))) { PHALCON_OBS_VAR(id); phalcon_array_fetch_string(&id, json, SL("id"), PH_NOISY); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "setid", id); } if (phalcon_array_isset_string(json, SS("result"))) { PHALCON_OBS_VAR(result); phalcon_array_fetch_string(&result, json, SL("result"), PH_NOISY); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "setresult", result); } if (phalcon_array_isset_string(json, SS("error"))) { PHALCON_OBS_VAR(error); phalcon_array_fetch_string(&error, json, SL("error"), PH_NOISY); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "seterror", error); } } } RETURN_CTOR(jsonrpc_response); }