/** * Gets the column name in MySQL * * @param Phalcon\Db\ColumnInterface $column * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){ zval *column, size = {}, column_type = {}, column_sql = {}, type_values = {}, slash = {}, *value, value_cslashes = {}, is_unsigned = {}, scale = {}, name = {}; int c, i = 0; phalcon_fetch_params(0, 1, 0, &column); PHALCON_VERIFY_INTERFACE_EX(column, phalcon_db_columninterface_ce, phalcon_db_exception_ce, 0); PHALCON_CALL_METHODW(&size, column, "getsize"); PHALCON_CALL_METHODW(&column_type, column, "gettype"); if (Z_TYPE(column_type) == IS_STRING) { PHALCON_CPY_WRT(&column_sql, &column_type); PHALCON_CALL_METHODW(&type_values, column, "gettypevalues"); if (PHALCON_IS_NOT_EMPTY(&type_values)) { ZVAL_STRING(&slash, "\""); if (Z_TYPE(type_values) == IS_ARRAY) { c = phalcon_fast_count_int(&type_values); phalcon_concat_self_str(&column_sql, SL("(")); ZEND_HASH_FOREACH_VAL(Z_ARRVAL(type_values), value) { i++; PHALCON_CALL_FUNCTIONW(&value_cslashes, "addcslashes", value, &slash); if (i < c) { PHALCON_SCONCAT_SVS(&column_sql, "\"", &value_cslashes, "\", "); } else { PHALCON_SCONCAT_SVS(&column_sql, "\"", &value_cslashes, "\""); } } ZEND_HASH_FOREACH_END();
/** * Draws a polygon * *<code> * $coordinates = array( array( 'x' => 4, 'y' => 6 ), array( 'x' => 8, 'y' => 10 ) ); * $image->polygon($coordinates); *</code> * * @param array $coordinates array of x and y * @param string $color * @return Phalcon\Image\Adapter\GD */ PHP_METHOD(Phalcon_Image_Adapter_GD, polygon){ zval *coordinates, *color = NULL, image = {}, rgb = {}, r = {}, g = {}, b = {}, imagecolor = {}, *point, points = {}, num_points = {}; phalcon_fetch_params(0, 1, 1, &coordinates, &color); if (!color) { color = &PHALCON_GLOBAL(z_null); } if (!phalcon_fast_count_ev(coordinates)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_image_exception_ce, "Coordinates must be not empty"); return; } phalcon_return_property(&image, getThis(), SL("_image")); if (Z_TYPE(image) == IS_RESOURCE) { PHALCON_CALL_METHODW(&rgb, getThis(), "getcolorrbg", color); phalcon_array_fetch_long(&r, &rgb, 0, PH_NOISY); phalcon_array_fetch_long(&g, &rgb, 1, PH_NOISY); phalcon_array_fetch_long(&b, &rgb, 2, PH_NOISY); PHALCON_CALL_FUNCTIONW(&imagecolor, "imagecolorallocate", &image, &r, &g, &b); array_init(&points); ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(coordinates), point) { zval x = {}, y = {}; if (Z_TYPE_P(point) == IS_ARRAY) { if (phalcon_fast_count_int(point) != 2) { PHALCON_THROW_EXCEPTION_STRW(phalcon_image_exception_ce, "Coordinates point error"); return; } if (!phalcon_array_isset_fetch_long(&x, point, 0)) { phalcon_array_fetch_str(&x, point, SL("x"), PH_NOISY); } if (!phalcon_array_isset_fetch_long(&y, point, 0)) { phalcon_array_fetch_str(&y, point, SL("y"), PH_NOISY); } phalcon_array_append(&points, &x, PH_COPY); phalcon_array_append(&points, &y, PH_COPY); } else { phalcon_array_append(&points, &_p->val, PH_COPY); _p++; phalcon_array_append(&points, &_p->val, PH_COPY); } phalcon_increment(&num_points); } ZEND_HASH_FOREACH_END();
/** * Prepare an HTML string of information about a single variable. */ PHP_METHOD(Phalcon_Debug_Dump, output){ zval *variable, *name = NULL, *tab = NULL, *space, *tmp = NULL, *new_tab = NULL; zval *output = NULL, *str = NULL, *type = NULL, *style = NULL, *count = NULL, *key = NULL, *value = NULL, *replace_pairs = NULL; zval *class_name = NULL, *objects, *detailed = NULL, *properties = NULL, *methods = NULL, *method = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &variable, &name, &tab); if (!name) { name = PHALCON_GLOBAL(z_null); } else if (!PHALCON_IS_EMPTY(name)) { PHALCON_CONCAT_SVS(return_value, "var ", name, " "); } if (!tab) { tab = PHALCON_GLOBAL(z_one); } PHALCON_INIT_VAR(space); ZVAL_STRING(space, " ", 1); if (Z_TYPE_P(variable) == IS_ARRAY) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style =':style'>Array</b> (<span style =':style'>:count</span>) (\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "arr", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(count); ZVAL_LONG(count, phalcon_fast_count_int(variable TSRMLS_CC)); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":count"), count, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); phalcon_concat_self(&return_value, output TSRMLS_CC); phalcon_is_iterable(variable, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); phalcon_concat_self(&return_value, tmp TSRMLS_CC); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "[<span style=':style'>:key</span>] => ", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "arr", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":key"), key, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); phalcon_concat_self(&return_value, output TSRMLS_CC); if (PHALCON_IS_LONG(tab, 1) && !PHALCON_IS_EMPTY(name) && !phalcon_is_numeric(key) && PHALCON_IS_IDENTICAL(name, key)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } else { PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_SELF(&tmp, "output", value, PHALCON_GLOBAL(z_null), new_tab); PHALCON_SCONCAT_VS(return_value, tmp, "\n"); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); } else if (Z_TYPE_P(variable) == IS_OBJECT) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Object</b> :class", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, variable, 0 TSRMLS_CC); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":class"), class_name, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_INIT_NVAR(class_name); phalcon_get_parent_class(class_name, variable, 0 TSRMLS_CC); if (zend_is_true(class_name)) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, " <b style=':style'>extends</b> :parent", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":parent"), class_name, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } PHALCON_SCONCAT_STR(return_value, " (\n"); objects = phalcon_fetch_nproperty_this(this_ptr, SL("_objects"), PH_NOISY TSRMLS_CC); if (phalcon_fast_in_array(variable, objects TSRMLS_CC)) { PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, "[already listed]\n"); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, ")"); RETURN_MM(); } phalcon_update_property_array_append(this_ptr, SL("_objects"), variable TSRMLS_CC); detailed = phalcon_fetch_nproperty_this(this_ptr, SL("_detailed"), PH_NOISY TSRMLS_CC); PHALCON_INIT_NVAR(properties); phalcon_get_object_vars(properties, variable, !zend_is_true(detailed) TSRMLS_CC); phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "-><span style=':style'>:key</span> (<span style=':style'>:type</span>) = ", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":key"), key, PH_COPY); if (PHALCON_PROPERTY_IS_PUBLIC_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("public"), PH_COPY); } else if (PHALCON_PROPERTY_IS_PRIVATE_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("private"), PH_COPY); } else if (PHALCON_PROPERTY_IS_PROTECTED_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("protected"), PH_COPY); } PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_SELF(&tmp, "output", value, PHALCON_GLOBAL(z_null), new_tab); PHALCON_SCONCAT_VS(return_value, tmp, ")\n"); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(methods); phalcon_get_class_methods(methods, variable, !zend_is_true(detailed) TSRMLS_CC); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, ":class <b style=':style'>methods</b>: (<span style=':style'>:count</span>) (\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, variable, 0 TSRMLS_CC); PHALCON_INIT_NVAR(count); ZVAL_LONG(count, phalcon_fast_count_int(methods TSRMLS_CC)); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":class"), class_name, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":count"), count, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); phalcon_is_iterable(methods, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(method); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, new_tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "-><span style=':style'>:method</span>();\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":method"), method, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, "\n"); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, ")"); } else if (Z_TYPE_P(variable) == IS_LONG) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Integer</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "int", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_DOUBLE) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Float</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "float", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (phalcon_is_numeric_ex(variable)) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Numeric string</b> (<span style=':style'>:length</span>) \"<span style=':style'>:var</span>\"", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "num", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string_long(&replace_pairs, SL(":length"), Z_STRLEN_P(variable), PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_STRING) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>String</b> (<span style=':style'>:length</span>) \"<span style=':style'>:var</span>\"", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "str", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string_long(&replace_pairs, SL(":length"), Z_STRLEN_P(variable), PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_BOOL) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Boolean</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "bool", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); if (zend_is_true(variable)) { phalcon_array_update_string_string(&replace_pairs, SL(":var"), SL("TRUE") , PH_COPY); } else { phalcon_array_update_string_string(&replace_pairs, SL(":var"), SL("FALSE") , PH_COPY); } PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_NULL) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>NULL</b>", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "null", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "(<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "other", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } RETURN_MM(); }