int phalcon_ob_end_clean() { if (phalcon_ob_get_level() < 1) { php_error_docref("ref.outcontrol", E_NOTICE, "failed to delete buffer. No buffer to delete"); return FAILURE; } return php_output_discard(); }
int phalcon_ob_flush() { if (phalcon_ob_get_level() < 1) { php_error_docref("ref.outcontrol", E_NOTICE, "failed to flush buffer. No buffer to flush"); return FAILURE; } return php_output_flush(); }
/** * 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, *escaped_message = NULL; zval *html, *version, *file, *line, *show_back_trace; zval *data_vars, *trace, *trace_item = NULL, *n = NULL, *html_item = NULL; zval *_REQUEST, *value = NULL, *key_request = NULL, *_SERVER; zval *key_server = NULL, *files, *key_file = NULL; zval *memory, *data_var = NULL, *key_var = NULL, *variable = NULL, *dumped_argument = NULL; zval *js_sources; HashTable *ah0, *ah1, *ah2, *ah3, *ah4; HashPosition hp0, hp1, hp2, hp3, hp4; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &exception); /** * Cancel the output buffer if active */ if (phalcon_ob_get_level(TSRMLS_C) > 0) { phalcon_ob_end_clean(TSRMLS_C); } PHALCON_OBS_VAR(is_active); phalcon_read_static_property(&is_active, SL("phalcon\\debug"), SL("_isActive") TSRMLS_CC); /** * Avoid that multiple exceptions being showed */ if (zend_is_true(is_active)) { PHALCON_INIT_VAR(message); phalcon_call_method(message, exception, "getmessage"); zend_print_zval(message, 0); } PHALCON_INIT_NVAR(is_active); ZVAL_BOOL(is_active, 1); /** * Globally block the debug component to avoid other exceptions must be shown */ phalcon_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, exception, 0 TSRMLS_CC); PHALCON_INIT_NVAR(message); phalcon_call_method(message, exception, "getmessage"); /** * CSS static sources to style the error presentation */ PHALCON_INIT_VAR(css_sources); 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><title>", class_name, ": ", escaped_message, "</title>"); PHALCON_SCONCAT_VS(html, css_sources, "</head><body>"); /** * Get the version link */ PHALCON_INIT_VAR(version); phalcon_call_method(version, this_ptr, "getversion"); phalcon_concat_self(&html, version TSRMLS_CC); PHALCON_INIT_VAR(file); phalcon_call_method(file, exception, "getfile"); PHALCON_INIT_VAR(line); phalcon_call_method(line, exception, "getline"); /** * 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\">", 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_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_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_INIT_VAR(trace); 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_INIT_NVAR(html_item); phalcon_call_method_p2(html_item, this_ptr, "showtraceitem", n, trace_item); 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); phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); 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); 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); phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); 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_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_server, "</td><td>", value, "</td></tr>"); zend_hash_move_forward_ex(ah2, &hp2); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Show included files */ PHALCON_INIT_VAR(files); phalcon_call_func(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_INIT_NVAR(dumped_argument); phalcon_call_method_p1(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_INIT_VAR(js_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); PHALCON_INIT_NVAR(is_active); ZVAL_BOOL(is_active, 0); /** * Unlock the exception renderer */ phalcon_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); 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; }