/** * Assigns default values to generated tags by helpers * * <code> * //Assigning "peter" to "name" component * Phalcon\Tag::setDefault("name", "peter"); * * //Later in the view * echo Phalcon\Tag::textField("name"); //Will have the value "peter" by default * </code> * * @param string $id * @param string $value */ PHP_METHOD(Phalcon_Tag, setDefault){ zval *id, *value; zval *t0 = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &id, &value); if (Z_TYPE_P(value) != IS_NULL) { if (PHALCON_IS_SCALAR(value)) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "Only scalar values can be assigned to UI components"); return; } } PHALCON_OBSERVE_VAR(t0); phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); if (Z_TYPE_P(t0) != IS_ARRAY) { convert_to_array(t0); } phalcon_array_update_zval(&t0, id, &value, PH_COPY TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), t0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Produces an string representation of a variable * * @param mixed $variable * @return string */ PHP_METHOD(Phalcon_Debug, _getVarDump){ zval *variable, *class_name, *dumped_object; zval *array_dump = NULL, *dump = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &variable); if (PHALCON_IS_SCALAR(variable)) { /** * Boolean variables are represented as 'true'/'false' */ if (Z_TYPE_P(variable) == IS_BOOL) { if (zend_is_true(variable)) { RETURN_MM_STRING("true", 1); } else { RETURN_MM_STRING("false", 1); } } /** * String variables are escaped to avoid XSS injections */ if (Z_TYPE_P(variable) == IS_STRING) { phalcon_call_method_p1(return_value, this_ptr, "_escapestring", variable); RETURN_MM(); } /** * Other scalar variables are just converted to strings */ RETURN_CCTOR(variable); } /** * If the variable is an object print its class name */ if (Z_TYPE_P(variable) == IS_OBJECT) { PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, variable, 0 TSRMLS_CC); /** * Try to check for a 'dump' method, this surely produces a better printable * representation */ if (phalcon_method_exists_ex(variable, SS("dump") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(dumped_object); phalcon_call_method(dumped_object, variable, "dump"); /** * dump() must return an array, generate a recursive representation using * getArrayDump */ PHALCON_INIT_VAR(array_dump); phalcon_call_method_p1(array_dump, this_ptr, "_getarraydump", dumped_object); PHALCON_INIT_VAR(dump); PHALCON_CONCAT_SVSVS(dump, "Object(", class_name, ": ", array_dump, ")"); } else { /** * If dump() is not available just print the class name */ PHALCON_INIT_NVAR(dump); PHALCON_CONCAT_SVS(dump, "Object(", class_name, ")</span>"); } RETURN_CTOR(dump); } /** * Recursively process the array and enclose it in Array() */ if (Z_TYPE_P(variable) == IS_ARRAY) { PHALCON_INIT_NVAR(array_dump); phalcon_call_method_p1(array_dump, this_ptr, "_getarraydump", variable); PHALCON_CONCAT_SVS(return_value, "Array(", array_dump, ")"); RETURN_MM(); } /** * Null variables are represented as 'null' * Other types are represented by its type */ RETURN_MM_STRING(zend_zval_type_name(variable), 1); }
/** * Produces a recursive representation of an array * * @param array $argument * @return string */ PHP_METHOD(Phalcon_Debug, _getArrayDump){ zval *argument, *n = NULL, *number_arguments, *one, *dump; zval *v = NULL, *k = NULL, *var_dump = NULL, *escaped_string = NULL, *next = NULL, *array_dump = NULL; zval *class_name = NULL, *joined_dump; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &argument, &n); if (!n) { PHALCON_INIT_VAR(n); ZVAL_LONG(n, 0); } PHALCON_INIT_VAR(number_arguments); phalcon_fast_count(number_arguments, argument TSRMLS_CC); if (PHALCON_LT_LONG(n, 3)) { if (PHALCON_GT_LONG(number_arguments, 0)) { if (PHALCON_LT_LONG(number_arguments, 10)) { PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_INIT_VAR(dump); array_init(dump); phalcon_is_iterable(argument, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(k, ah0, hp0); PHALCON_GET_HVALUE(v); if (PHALCON_IS_SCALAR(v)) { if (PHALCON_IS_STRING(v, "")) { PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVS(var_dump, "[", k, "] => (empty string)"); } else { PHALCON_INIT_NVAR(escaped_string); phalcon_call_method_p1(escaped_string, this_ptr, "_escapestring", v); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSV(var_dump, "[", k, "] => ", escaped_string); } phalcon_array_append(&dump, var_dump, PH_SEPARATE); } else { if (Z_TYPE_P(v) == IS_ARRAY) { PHALCON_INIT_NVAR(next); phalcon_add_function(next, n, one TSRMLS_CC); PHALCON_INIT_NVAR(array_dump); phalcon_call_method_p2(array_dump, this_ptr, "_getarraydump", v, next); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] => Array(", array_dump, ")"); phalcon_array_append(&dump, var_dump, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); continue; } if (Z_TYPE_P(v) == IS_OBJECT) { PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, v, 0 TSRMLS_CC); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] => Object(", class_name, ")"); phalcon_array_append(&dump, var_dump, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); continue; } if (Z_TYPE_P(v) == IS_NULL) { PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVS(var_dump, "[", k, "] => null"); phalcon_array_append(&dump, var_dump, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); continue; } PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSV(var_dump, "[", k, "] => ", v); phalcon_array_append(&dump, var_dump, PH_SEPARATE); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(joined_dump); phalcon_fast_join_str(joined_dump, SL(", "), dump TSRMLS_CC); RETURN_CTOR(joined_dump); } RETURN_NCTOR(number_arguments); } } RETURN_MM_NULL(); }
/** * Produces a recursive representation of an array * * @param array $argument * @return string */ PHP_METHOD(Phalcon_Debug, _getArrayDump) { zval *argument, *n = NULL, *number_arguments, *dump; zval *v = NULL, *var_dump = NULL, *escaped_string = NULL, *next = NULL, *array_dump = NULL; zval *class_name = NULL, *joined_dump; zend_string *str_key; ulong idx; PHALCON_MM_GROW(); phalcon_fetch_params(0, 1, 1, &argument, &n); if (!n) { PHALCON_INIT_VAR(n); ZVAL_LONG(n, 0); } PHALCON_INIT_VAR(number_arguments); phalcon_fast_count(number_arguments, argument); if (PHALCON_LT_LONG(n, 3)) { if (PHALCON_GT_LONG(number_arguments, 0)) { if (PHALCON_LT_LONG(number_arguments, 10)) { PHALCON_INIT_VAR(dump); array_init(dump); ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(argument), idx, str_key, v) { zval tmp; if (str_key) { ZVAL_STR(&tmp, str_key); } else { ZVAL_LONG(&tmp, idx); } if (PHALCON_IS_SCALAR(v)) { if (PHALCON_IS_STRING(v, "")) { PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVS(var_dump, "[", &tmp, "] => (empty string)"); } else { PHALCON_CALL_METHOD(&escaped_string, getThis(), "_escapestring", v); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSV(var_dump, "[", &tmp, "] => ", escaped_string); } phalcon_array_append(dump, var_dump, PH_COPY); } else { if (Z_TYPE_P(v) == IS_ARRAY) { PHALCON_INIT_NVAR(next); phalcon_add_function(next, n, &PHALCON_GLOBAL(z_one)); PHALCON_CALL_METHOD(&array_dump, getThis(), "_getarraydump", v, next); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSVS(var_dump, "[", &tmp, "] => Array(", array_dump, ")"); phalcon_array_append(dump, var_dump, PH_COPY); continue; } if (Z_TYPE_P(v) == IS_OBJECT) { zend_class_entry *ce = Z_OBJCE_P(v); PHALCON_INIT_NVAR(class_name); ZVAL_NEW_STR(class_name, ce->name); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSVS(var_dump, "[", &tmp, "] => Object(", class_name, ")"); phalcon_array_append(dump, var_dump, PH_COPY); continue; } if (Z_TYPE_P(v) == IS_NULL) { PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVS(var_dump, "[", &tmp, "] => null"); phalcon_array_append(dump, var_dump, PH_COPY); continue; } PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSV(var_dump, "[", &tmp, "] => ", v); phalcon_array_append(dump, var_dump, PH_COPY); } } ZEND_HASH_FOREACH_END(); PHALCON_INIT_VAR(joined_dump); phalcon_fast_join_str(joined_dump, SL(", "), dump); RETURN_CTOR(joined_dump); } RETURN_NCTOR(number_arguments); }