/** * Concatenates strings using the separator only once without duplication in places concatenation * * <code> * $str = Phalcon\Text::concat("/", "/tmp/", "/folder_1/", "/folder_2", "folder_3/"); * echo $str; // /tmp/folder_1/folder_2/folder_3/ * </code> * * @param string separator * @param string a * @param string b * @param string ...N */ PHP_METHOD(Phalcon_Text, concat){ zval *separator, *a, *b; zval *arg_num = NULL, *arg_list = NULL, *offset, *args = NULL; zval *c = NULL, *a_trimmed = NULL, *b_trimmed = NULL, *c_trimmed = NULL, *tmp = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &separator, &a, &b); PHALCON_CALL_FUNCTION(&arg_num, "func_num_args"); if (Z_LVAL_P(arg_num) > 3) { PHALCON_CALL_FUNCTION(&arg_list, "func_get_args"); PHALCON_INIT_VAR(offset); ZVAL_LONG(offset, 3); PHALCON_CALL_FUNCTION(&args, "array_slice", arg_list, offset); phalcon_is_iterable(args, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(c); PHALCON_INIT_NVAR(b_trimmed); phalcon_fast_trim(b_trimmed, b, separator, PHALCON_TRIM_RIGHT TSRMLS_CC); PHALCON_INIT_NVAR(c_trimmed); phalcon_fast_trim(c_trimmed, c, separator, PHALCON_TRIM_LEFT TSRMLS_CC); PHALCON_INIT_NVAR(tmp); PHALCON_CONCAT_VVV(tmp, b_trimmed, separator, c_trimmed) PHALCON_CPY_WRT(b, tmp); zend_hash_move_forward_ex(ah0, &hp0); } } PHALCON_INIT_NVAR(a_trimmed); phalcon_fast_trim(a_trimmed, a, separator, PHALCON_TRIM_RIGHT TSRMLS_CC); PHALCON_INIT_NVAR(b_trimmed); phalcon_fast_trim(b_trimmed, b, separator, PHALCON_TRIM_LEFT TSRMLS_CC); PHALCON_INIT_NVAR(tmp); PHALCON_CONCAT_VVV(tmp, a_trimmed, separator, b_trimmed) RETURN_CTOR(tmp); }
/** * Returns the active version (string) * * <code> * echo Phalcon\Version::get(); * </code> * * @return string */ PHP_METHOD(Phalcon_Version, get){ zval *version, *major, *medium, *minor, *special, *special_number; zval *result, *suffix = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(version); PHALCON_CALL_SELF(version, this_ptr, "_getversion"); PHALCON_OBS_VAR(major); phalcon_array_fetch_long(&major, version, 0, PH_NOISY); PHALCON_OBS_VAR(medium); phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); PHALCON_OBS_VAR(minor); phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); PHALCON_OBS_VAR(special); phalcon_array_fetch_long(&special, version, 3, PH_NOISY); PHALCON_OBS_VAR(special_number); phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); PHALCON_INIT_VAR(result); PHALCON_CONCAT_VSVSVS(result, major, ".", medium, ".", minor, " "); switch (phalcon_get_intval(special)) { case 1: PHALCON_INIT_VAR(suffix); PHALCON_CONCAT_SV(suffix, "ALPHA ", special_number); break; case 2: PHALCON_INIT_NVAR(suffix); PHALCON_CONCAT_SV(suffix, "BETA ", special_number); break; case 3: PHALCON_INIT_NVAR(suffix); PHALCON_CONCAT_SV(suffix, "RC ", special_number); break; default: PHALCON_INIT_NVAR(suffix); ZVAL_STRING(suffix, "", 1); break; } phalcon_concat_self(&result, suffix TSRMLS_CC); phalcon_fast_trim(return_value, result, PHALCON_TRIM_BOTH TSRMLS_CC); RETURN_MM(); }
/** * Makes an underscored or dashed phrase human-readable * * <code> * echo Phalcon\Text::humanize('start-a-horse'); // 'start a horse' * echo Phalcon\Text::humanize('five_cats'); // 'five cats' * </code> */ PHP_METHOD(Phalcon_Text, humanize){ zval *str, *trimmed, *pattern, *replacement; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &str); PHALCON_INIT_VAR(trimmed); phalcon_fast_trim(trimmed, str, NULL, PHALCON_TRIM_BOTH TSRMLS_CC); PHALCON_INIT_VAR(pattern); ZVAL_STRING(pattern, "#[_-]+#", 1); PHALCON_INIT_VAR(replacement); ZVAL_STRING(replacement, " ", 1); PHALCON_RETURN_CALL_FUNCTION("preg_replace", pattern, replacement, trimmed); RETURN_MM(); }
/** * Shows a backtrace item * * @param int $n * @param array $trace */ PHP_METHOD(Phalcon_Debug, showTraceItem){ zval *n, *trace, *space, *two_spaces, *underscore; zval *minus, *html, *class_name, *pattern, *is_phalcon_class; zval *namespace_separator, *prepare_uri_class; zval *class_reflection, *is_internal = NULL, *lower_class_name; zval *prepare_internal_class, *type, *function_name = NULL; zval *function_reflection, *prepared_function_name; zval *trace_args, *arguments, *argument = NULL, *dumped_argument = NULL; zval *span_argument = NULL, *joined_arguments, *one; zval *file, *line, *show_files, *lines, *number_lines; zval *show_file_fragment, *seven, *before_line; zval *first_line = NULL, *five, *after_line, *last_line = NULL; zval *comment_pattern, *utf8, *ent_compat, *tab; zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL; zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL; zval *escaped_line = NULL; HashTable *ah0; HashPosition hp0; zval **hd; zend_class_entry *ce0, *ce1; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &n, &trace); PHALCON_INIT_VAR(space); ZVAL_STRING(space, " ", 1); PHALCON_INIT_VAR(two_spaces); ZVAL_STRING(two_spaces, " ", 1); PHALCON_INIT_VAR(underscore); ZVAL_STRING(underscore, "_", 1); PHALCON_INIT_VAR(minus); ZVAL_STRING(minus, "-", 1); /** * Every trace in the backtrace have a unique number */ PHALCON_INIT_VAR(html); PHALCON_CONCAT_SVS(html, "<tr><td align=\"right\" valign=\"top\" class=\"error-number\">#", n, "</td><td>"); if (phalcon_array_isset_string(trace, SS("class"))) { PHALCON_OBS_VAR(class_name); phalcon_array_fetch_string(&class_name, trace, SL("class"), PH_NOISY); PHALCON_INIT_VAR(pattern); ZVAL_STRING(pattern, "/^Phalcon/", 1); PHALCON_INIT_VAR(is_phalcon_class); phalcon_preg_match(is_phalcon_class, pattern, class_name, NULL TSRMLS_CC); /** * We assume that classes starting by Phalcon are framework's classes */ if (zend_is_true(is_phalcon_class)) { PHALCON_INIT_VAR(namespace_separator); ZVAL_STRING(namespace_separator, "\\", 1); /** * Prepare the class name according to the Phalcon's conventions */ PHALCON_INIT_VAR(prepare_uri_class); phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name); /** * Generate a link to the official docs */ PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://docs.phalconphp.com/en/latest/api/", prepare_uri_class, ".html\">", class_name, "</a></span>"); } else { ce0 = zend_fetch_class(SL("ReflectionClass"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_VAR(class_reflection); object_init_ex(class_reflection, ce0); if (phalcon_has_constructor(class_reflection TSRMLS_CC)) { phalcon_call_method_p1_noret(class_reflection, "__construct", class_name); } /** * Check if classes are PHP's classes */ PHALCON_INIT_VAR(is_internal); phalcon_call_method(is_internal, class_reflection, "isinternal"); if (zend_is_true(is_internal)) { PHALCON_INIT_VAR(lower_class_name); phalcon_fast_strtolower(lower_class_name, class_name); PHALCON_INIT_VAR(prepare_internal_class); phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name); /** * Generate a link to the official docs */ PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://php.net/manual/en/class.", prepare_internal_class, ".php\">", class_name, "</a></span>"); } else { PHALCON_SCONCAT_SVS(html, "<span class=\"error-class\">", class_name, "</span>"); } } /** * Object access operator: static/instance */ PHALCON_OBS_VAR(type); phalcon_array_fetch_string(&type, trace, SL("type"), PH_NOISY); phalcon_concat_self(&html, type TSRMLS_CC); } /** * Normally the backtrace contains only classes */ if (phalcon_array_isset_string(trace, SS("class"))) { PHALCON_OBS_VAR(function_name); phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY); PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>"); } else { PHALCON_OBS_NVAR(function_name); phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY); /** * Check if the function exists */ if (phalcon_function_exists(function_name TSRMLS_CC) == SUCCESS) { ce1 = zend_fetch_class(SL("ReflectionFunction"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_VAR(function_reflection); object_init_ex(function_reflection, ce1); if (phalcon_has_constructor(function_reflection TSRMLS_CC)) { phalcon_call_method_p1_noret(function_reflection, "__construct", function_name); } PHALCON_INIT_NVAR(is_internal); phalcon_call_method(is_internal, function_reflection, "isinternal"); /** * Internal functions links to the PHP documentation */ if (zend_is_true(is_internal)) { /** * Prepare function's name according to the conventions in the docs */ PHALCON_INIT_VAR(prepared_function_name); phalcon_fast_str_replace(prepared_function_name, underscore, minus, function_name); PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-function\"><a target=\"_new\" href=\"http://php.net/manual/en/function.", prepared_function_name, ".php\">", function_name, "</a></span>"); } else { PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>"); } } else { PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>"); } } /** * Check for arguments in the function */ if (phalcon_array_isset_string(trace, SS("args"))) { PHALCON_OBS_VAR(trace_args); phalcon_array_fetch_string(&trace_args, trace, SL("args"), PH_NOISY); if (phalcon_fast_count_ev(trace_args TSRMLS_CC)) { PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(argument); /** * Every argument is generated using _getVarDump */ PHALCON_INIT_NVAR(dumped_argument); phalcon_call_method_p1(dumped_argument, this_ptr, "_getvardump", argument); PHALCON_INIT_NVAR(span_argument); PHALCON_CONCAT_SVS(span_argument, "<span class=\"error-parameter\">", dumped_argument, "</span>"); /** * Append the HTML generated to the argument's list */ phalcon_array_append(&arguments, span_argument, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } /** * Join all the arguments */ PHALCON_INIT_VAR(joined_arguments); phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC); PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")"); } else { phalcon_concat_self_str(&html, SL("()") TSRMLS_CC); } } /** * When 'file' is present, it usually means the function is provided by the user */ if (phalcon_array_isset_string(trace, SS("file"))) { PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_OBS_VAR(file); phalcon_array_fetch_string(&file, trace, SL("file"), PH_NOISY); PHALCON_OBS_VAR(line); phalcon_array_fetch_string(&line, trace, SL("line"), PH_NOISY); /** * Realpath to the file and its line using a special header */ PHALCON_SCONCAT_SVSVS(html, "<br/><div class=\"error-file\">", file, " (", line, ")</div>"); PHALCON_OBS_VAR(show_files); phalcon_read_property_this(&show_files, this_ptr, SL("_showFiles"), PH_NOISY_CC); /** * The developer can change if the files must be opened or not */ if (zend_is_true(show_files)) { /** * Open the file to an array using 'file', this respects the openbase-dir directive */ PHALCON_INIT_VAR(lines); phalcon_call_func_p1(lines, "file", file); PHALCON_INIT_VAR(number_lines); phalcon_fast_count(number_lines, lines TSRMLS_CC); PHALCON_OBS_VAR(show_file_fragment); phalcon_read_property_this(&show_file_fragment, this_ptr, SL("_showFileFragment"), PH_NOISY_CC); /** * File fragments just show a piece of the file where the exception is located */ if (zend_is_true(show_file_fragment)) { /** * Take seven lines back to the current exception's line, @TODO add an option for * this */ PHALCON_INIT_VAR(seven); ZVAL_LONG(seven, 7); PHALCON_INIT_VAR(before_line); sub_function(before_line, line, seven TSRMLS_CC); /** * Check for overflows */ if (PHALCON_LT_LONG(before_line, 1)) { PHALCON_CPY_WRT(first_line, one); } else { PHALCON_CPY_WRT(first_line, before_line); } /** * Take five lines after the current exception's line, @TODO add an option for this */ PHALCON_INIT_VAR(five); ZVAL_LONG(five, 5); PHALCON_INIT_VAR(after_line); phalcon_add_function(after_line, line, five TSRMLS_CC); /** * Check for overflows */ if (PHALCON_GT(after_line, number_lines)) { PHALCON_CPY_WRT(last_line, number_lines); } else { PHALCON_CPY_WRT(last_line, after_line); } PHALCON_SCONCAT_SVSVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums:", first_line, "'>"); } else { PHALCON_CPY_WRT(first_line, one); PHALCON_CPY_WRT(last_line, number_lines); PHALCON_SCONCAT_SVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums error-scroll'>"); } PHALCON_INIT_VAR(comment_pattern); ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1); /** * We assume the file is utf-8 encoded, @TODO add an option for this */ PHALCON_INIT_VAR(utf8); ZVAL_STRING(utf8, "UTF-8", 1); /** * Don't escape quotes */ PHALCON_INIT_VAR(ent_compat); ZVAL_LONG(ent_compat, 2); PHALCON_INIT_VAR(tab); ZVAL_STRING(tab, "\t", 1); PHALCON_INIT_VAR(comment); ZVAL_STRING(comment, "* /", 1); PHALCON_CPY_WRT(i, first_line); while (1) { if (PHALCON_LE(i, last_line)) { } else { break; } /** * Current line in the file */ PHALCON_INIT_NVAR(line_position); sub_function(line_position, i, one TSRMLS_CC); /** * Current line content in the piece of file */ PHALCON_OBS_NVAR(current_line); phalcon_array_fetch(¤t_line, lines, line_position, PH_NOISY); /** * File fragments are cleaned, removing tabs and comments */ if (zend_is_true(show_file_fragment)) { if (PHALCON_IS_EQUAL(i, first_line)) { PHALCON_INIT_NVAR(trimmed); phalcon_fast_trim(trimmed, current_line, PHALCON_TRIM_RIGHT TSRMLS_CC); PHALCON_INIT_NVAR(is_comment); phalcon_preg_match(is_comment, comment_pattern, current_line, NULL TSRMLS_CC); if (zend_is_true(is_comment)) { PHALCON_INIT_NVAR(spaced_current_line); phalcon_fast_str_replace(spaced_current_line, comment, space, current_line); PHALCON_CPY_WRT(current_line, spaced_current_line); } } } /** * Print a non break space if the current line is a line break, this allows to show * the html zebra properly */ if (PHALCON_IS_STRING(current_line, "\n")) { phalcon_concat_self_str(&html, SL(" \n") TSRMLS_CC); } else { if (PHALCON_IS_STRING(current_line, "\r\n")) { phalcon_concat_self_str(&html, SL(" \n") TSRMLS_CC); } else { PHALCON_INIT_NVAR(spaced_current_line); phalcon_fast_str_replace(spaced_current_line, tab, two_spaces, current_line); PHALCON_INIT_NVAR(escaped_line); phalcon_call_func_p3(escaped_line, "htmlentities", spaced_current_line, ent_compat, utf8); phalcon_concat_self(&html, escaped_line TSRMLS_CC); } } PHALCON_SEPARATE(i); phalcon_increment(i); } phalcon_concat_self_str(&html, SL("</pre>") TSRMLS_CC); } } phalcon_concat_self_str(&html, SL("</td></tr>") TSRMLS_CC); RETURN_CTOR(html); }
PHP_METHOD(Phalcon_Http_Client_Header, parse){ zval *content, *content_parts = NULL, *key = NULL, *header = NULL, *header_parts = NULL, *name = NULL, *value = NULL, *trimmed = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &content); if (PHALCON_IS_EMPTY(content)) { RETURN_MM_FALSE; } if (Z_TYPE_P(content) == IS_STRING) { PHALCON_INIT_VAR(content_parts); phalcon_fast_explode_str(content_parts, SL("\r\n"), content); } else if (Z_TYPE_P(content) == IS_ARRAY) { PHALCON_CPY_WRT_CTOR(content_parts, content); } else { RETURN_MM_FALSE; } phalcon_is_iterable(content_parts, &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(header); if (Z_TYPE_P(header) == IS_STRING) { PHALCON_INIT_NVAR(header_parts); if (phalcon_memnstr_str(header , SL(":"))) { phalcon_fast_explode_str(header_parts, SL(":"), header); } else { if (phalcon_start_with_str(header , SL("HTTP/"))) { phalcon_fast_explode_str(header_parts, SL(" "), header); if (Z_TYPE_P(header_parts) == IS_ARRAY && phalcon_array_isset_long(header_parts, 1) && phalcon_array_isset_long(header_parts, 2)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch_long(&value, header_parts, 1, PH_NOISY); phalcon_update_property_this(this_ptr, SL("_status_code"), value TSRMLS_CC); PHALCON_OBS_NVAR(value); phalcon_array_fetch_long(&value, header_parts, 2, PH_NOISY); phalcon_update_property_this(this_ptr, SL("_status_message"), value TSRMLS_CC); } } zend_hash_move_forward_ex(ah0, &hp0); continue; } } else { PHALCON_CPY_WRT_CTOR(header_parts, header); } if (Z_TYPE_P(header_parts) == IS_ARRAY && phalcon_array_isset_long(header_parts, 0) && phalcon_array_isset_long(header_parts, 1)) { PHALCON_OBS_NVAR(name); phalcon_array_fetch_long(&name, header_parts, 0, PH_NOISY); PHALCON_OBS_NVAR(value); phalcon_array_fetch_long(&value, header_parts, 1, PH_NOISY); PHALCON_INIT_NVAR(trimmed); phalcon_fast_trim(trimmed, value, NULL, PHALCON_TRIM_BOTH TSRMLS_CC); PHALCON_CALL_METHOD(NULL, this_ptr, "set", name, trimmed); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_MM_RESTORE(); }
/** * Shows a backtrace item * * @param int $n * @param array $trace */ PHP_METHOD(Phalcon_Debug, showTraceItem){ zval *n, *trace, *link_format, *space, *two_spaces, *underscore; zval *minus, *html, *class_name; zval *namespace_separator, *prepare_uri_class; zval *lower_class_name, *prepared_function_name; zval *prepare_internal_class, *type, *function_name = NULL; zval *trace_args, *arguments, *argument = NULL, *dumped_argument = NULL; zval *span_argument = NULL, *joined_arguments, *z_one; zval *file, *line, *show_files, *lines = NULL, *number_lines; zval *show_file_fragment, *before_context, *before_line; zval *first_line = NULL, *after_context, *after_line, *last_line = NULL; zval *comment_pattern, *charset, *tab; zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL; zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL; zval *escaped_line = NULL, *formatted_file = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &n, &trace, &link_format); PHALCON_INIT_VAR(space); ZVAL_STRING(space, " ", 1); PHALCON_INIT_VAR(two_spaces); ZVAL_STRING(two_spaces, " ", 1); PHALCON_INIT_VAR(underscore); ZVAL_STRING(underscore, "_", 1); PHALCON_INIT_VAR(minus); ZVAL_STRING(minus, "-", 1); /** * Every trace in the backtrace have a unique number */ PHALCON_INIT_VAR(html); PHALCON_CONCAT_SVS(html, "<tr><td align=\"right\" valign=\"top\" class=\"error-number\">#", n, "</td><td>"); if (phalcon_array_isset_string(trace, SS("class"))) { zend_class_entry *class_ce; PHALCON_OBS_VAR(class_name); phalcon_array_fetch_string(&class_name, trace, SL("class"), PH_NOISY); class_ce = zend_fetch_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_SILENT TSRMLS_CC); if (!class_ce) { /* Unable to load the class, should never happen */ } else if (is_phalcon_class(class_ce)) { PHALCON_INIT_VAR(namespace_separator); ZVAL_STRING(namespace_separator, "\\", 1); /* Prepare the class name according to the Phalcon's conventions */ PHALCON_INIT_VAR(prepare_uri_class); phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name); /* Generate a link to the official docs */ PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://docs.phalconphp.com/en/latest/api/", prepare_uri_class, ".html\">", class_name, "</a></span>"); } else if (class_ce->type == ZEND_INTERNAL_CLASS) { PHALCON_INIT_VAR(lower_class_name); phalcon_fast_strtolower(lower_class_name, class_name); PHALCON_INIT_VAR(prepare_internal_class); phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name); /* Generate a link to the official docs */ PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-class\"><a target=\"_new\" href=\"http://php.net/manual/en/class.", prepare_internal_class, ".php\">", class_name, "</a></span>"); } else { PHALCON_SCONCAT_SVS(html, "<span class=\"error-class\">", class_name, "</span>"); } /** * Object access operator: static/instance */ PHALCON_OBS_VAR(type); phalcon_array_fetch_string(&type, trace, SL("type"), PH_NOISY); phalcon_concat_self(&html, type TSRMLS_CC); } /** * Normally the backtrace contains only classes */ if (phalcon_array_isset_string(trace, SS("class"))) { PHALCON_OBS_VAR(function_name); phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY); PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>"); } else { zend_function *func; PHALCON_OBS_NVAR(function_name); phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY); convert_to_string(function_name); /** * Check if the function exists */ if (phalcon_fetch_function(&func, Z_STRVAL_P(function_name), Z_STRLEN_P(function_name) TSRMLS_CC) == SUCCESS) { /** * Internal functions links to the PHP documentation */ if (func->type == ZEND_INTERNAL_FUNCTION) { /** * Prepare function's name according to the conventions in the docs */ PHALCON_INIT_VAR(prepared_function_name); phalcon_fast_str_replace(prepared_function_name, underscore, minus, function_name); PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-function\"><a target=\"_new\" href=\"http://php.net/manual/en/function.", prepared_function_name, ".php\">", function_name, "</a></span>"); } else { PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>"); } } else { PHALCON_SCONCAT_SVS(html, "<span class=\"error-function\">", function_name, "</span>"); } } /** * Check for arguments in the function */ if (phalcon_array_isset_string(trace, SS("args"))) { PHALCON_OBS_VAR(trace_args); phalcon_array_fetch_string(&trace_args, trace, SL("args"), PH_NOISY); if (phalcon_fast_count_ev(trace_args TSRMLS_CC)) { PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(argument); /** * Every argument is generated using _getVarDump */ PHALCON_CALL_METHOD(&dumped_argument, this_ptr, "_getvardump", argument); PHALCON_INIT_NVAR(span_argument); PHALCON_CONCAT_SVS(span_argument, "<span class=\"error-parameter\">", dumped_argument, "</span>"); /** * Append the HTML generated to the argument's list */ phalcon_array_append(&arguments, span_argument, PH_COPY); zend_hash_move_forward_ex(ah0, &hp0); } /** * Join all the arguments */ PHALCON_INIT_VAR(joined_arguments); phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC); PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")"); } else { phalcon_concat_self_str(&html, SL("()") TSRMLS_CC); } } /** * When 'file' is present, it usually means the function is provided by the user */ if (phalcon_array_isset_string(trace, SS("file"))) { z_one = PHALCON_GLOBAL(z_one); PHALCON_OBS_VAR(file); phalcon_array_fetch_string(&file, trace, SL("file"), PH_NOISY); PHALCON_OBS_VAR(line); phalcon_array_fetch_string(&line, trace, SL("line"), PH_NOISY); PHALCON_CALL_METHOD(&formatted_file, getThis(), "getfilelink", file, line, link_format); /** * Realpath to the file and its line using a special header */ PHALCON_SCONCAT_SVSVS(html, "<br/><div class=\"error-file\">", formatted_file, " (", line, ")</div>"); PHALCON_OBS_VAR(show_files); phalcon_read_property_this(&show_files, this_ptr, SL("_showFiles"), PH_NOISY TSRMLS_CC); /** * The developer can change if the files must be opened or not */ if (zend_is_true(show_files)) { /** * Open the file to an array using 'file', this respects the openbase-dir directive */ PHALCON_CALL_FUNCTION(&lines, "file", file); PHALCON_INIT_VAR(number_lines); phalcon_fast_count(number_lines, lines TSRMLS_CC); PHALCON_OBS_VAR(show_file_fragment); phalcon_read_property_this(&show_file_fragment, this_ptr, SL("_showFileFragment"), PH_NOISY TSRMLS_CC); /** * File fragments just show a piece of the file where the exception is located */ if (zend_is_true(show_file_fragment)) { /** * Take lines back to the current exception's line */ before_context = phalcon_fetch_nproperty_this(getThis(), SL("_beforeContext"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(before_line); phalcon_sub_function(before_line, line, before_context); /** * Check for overflows */ if (PHALCON_LT_LONG(before_line, 1)) { PHALCON_CPY_WRT_CTOR(first_line, z_one); } else { PHALCON_CPY_WRT(first_line, before_line); } /** * Take lines after the current exception's line */ after_context = phalcon_fetch_nproperty_this(getThis(), SL("_afterContext"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(after_line); phalcon_add_function(after_line, line, after_context); /** * Check for overflows */ if (PHALCON_GT(after_line, number_lines)) { PHALCON_CPY_WRT(last_line, number_lines); } else { PHALCON_CPY_WRT(last_line, after_line); } PHALCON_SCONCAT_SVSVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums:", first_line, "'>"); } else { PHALCON_CPY_WRT_CTOR(first_line, z_one); PHALCON_CPY_WRT(last_line, number_lines); PHALCON_SCONCAT_SVSVS(html, "<pre class='prettyprint highlight:", first_line, ":", line, " linenums error-scroll'>"); } PHALCON_INIT_VAR(comment_pattern); ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1); charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); PHALCON_INIT_VAR(tab); ZVAL_STRING(tab, "\t", 1); PHALCON_INIT_VAR(comment); ZVAL_STRING(comment, "* /", 1); PHALCON_CPY_WRT(i, first_line); while (PHALCON_LE(i, last_line)) { /** * Current line in the file */ PHALCON_INIT_NVAR(line_position); phalcon_sub_function(line_position, i, z_one); /** * Current line content in the piece of file */ PHALCON_OBS_NVAR(current_line); phalcon_array_fetch(¤t_line, lines, line_position, PH_NOISY); /** * File fragments are cleaned, removing tabs and comments */ if (zend_is_true(show_file_fragment)) { if (PHALCON_IS_EQUAL(i, first_line)) { PHALCON_INIT_NVAR(trimmed); phalcon_fast_trim(trimmed, current_line, NULL, PHALCON_TRIM_RIGHT TSRMLS_CC); PHALCON_INIT_NVAR(is_comment); RETURN_MM_ON_FAILURE(phalcon_preg_match(is_comment, comment_pattern, current_line, NULL TSRMLS_CC)); if (zend_is_true(is_comment)) { PHALCON_INIT_NVAR(spaced_current_line); phalcon_fast_str_replace(spaced_current_line, comment, space, current_line); PHALCON_CPY_WRT(current_line, spaced_current_line); } } } /** * Print a non break space if the current line is a line break, this allows to show * the html zebra properly */ if (PHALCON_IS_STRING(current_line, "\n")) { phalcon_concat_self_str(&html, SL(" \n") TSRMLS_CC); } else { if (PHALCON_IS_STRING(current_line, "\r\n")) { phalcon_concat_self_str(&html, SL(" \n") TSRMLS_CC); } else { PHALCON_INIT_NVAR(spaced_current_line); phalcon_fast_str_replace(spaced_current_line, tab, two_spaces, current_line); PHALCON_INIT_NVAR(escaped_line); phalcon_htmlentities(escaped_line, spaced_current_line, NULL, charset TSRMLS_CC); phalcon_concat_self(&html, escaped_line TSRMLS_CC); } } phalcon_increment(i); } phalcon_concat_self_str(&html, SL("</pre>") TSRMLS_CC); } } phalcon_concat_self_str(&html, SL("</td></tr>") TSRMLS_CC); RETURN_CTOR(html); }