Skip to content

Commit

Permalink
Remove error_api
Browse files Browse the repository at this point in the history
The traditional error_api system has now been completely removed. Some
of the functionality still lives inside MantisBT\Error but will be
replaced in due course with a better OO exception printer (one that can
be extended to work with HTML, SOAP, JSON, ...).

From now on, trigger_error should not be used to raise errors. Use the
OO "throw ExceptionClass($parameters)" approach instead.
  • Loading branch information
davidhicks committed Feb 25, 2012
1 parent b3405a0 commit c0827e0
Show file tree
Hide file tree
Showing 19 changed files with 9 additions and 266 deletions.
36 changes: 3 additions & 33 deletions application/MantisBT/Error.php
Expand Up @@ -36,8 +36,6 @@ class Error {

private static $parameters = array();

private static $proceedUrl = null;

public static function init(){
if( self::$handled === false ) {
// first run
Expand Down Expand Up @@ -95,7 +93,7 @@ public static function error_handler( $type, $error, $file, $line, $context ) {
self::init();
}

if( $type == E_WARNING || $type == E_USER_WARNING || null !== self::$proceedUrl ) {
if( $type == E_WARNING || $type == E_USER_WARNING ) {

switch( $type ) {
case E_WARNING:
Expand All @@ -109,9 +107,6 @@ public static function error_handler( $type, $error, $file, $line, $context ) {
}
$errorDescription = nl2br( $errorDescription );
echo '<p style="color:red">', $errorType, ': ', $errorDescription, '</p>';
if ( null !== self::$proceedUrl ) {
echo '<a href="', self::$proceedUrl, '">', lang_get( 'proceed' ), '</a>';
}

return true; // @todo true|false??
}
Expand Down Expand Up @@ -148,7 +143,7 @@ public static function display_errors( $noHeader = false ) {
}

$oblen = ob_get_length();
if( error_handled() && $oblen > 0 ) {
if( self::$handled === true && $oblen > 0 ) {
$oldContents = ob_get_contents();
}

Expand Down Expand Up @@ -296,8 +291,7 @@ public static function error_print_stack_trace( $stack ) {
array_shift( $stack );

foreach( $stack as $frame ) {
echo '<tr ', self::error_alternate_class(), '>';
echo '<td>', ( isset( $frame['file'] ) ? htmlentities( $frame['file'], ENT_COMPAT, 'UTF-8' ) : '-' ), '</td><td>', ( isset( $frame['line'] ) ? $frame['line'] : '-' ), '</td><td>', ( isset( $frame['class'] ) ? $frame['class'] : '-' ), '</td><td>', ( isset( $frame['type'] ) ? $frame['type'] : '-' ), '</td><td>', ( isset( $frame['function'] ) ? $frame['function'] : '-' ), '</td>';
echo '<tr><td>', ( isset( $frame['file'] ) ? htmlentities( $frame['file'], ENT_COMPAT, 'UTF-8' ) : '-' ), '</td><td>', ( isset( $frame['line'] ) ? $frame['line'] : '-' ), '</td><td>', ( isset( $frame['class'] ) ? $frame['class'] : '-' ), '</td><td>', ( isset( $frame['type'] ) ? $frame['type'] : '-' ), '</td><td>', ( isset( $frame['function'] ) ? $frame['function'] : '-' ), '</td>';

$args = array();
if( isset( $frame['args'] ) && !empty( $frame['args'] ) ) {
Expand Down Expand Up @@ -373,30 +367,6 @@ public static function error_string( $error ) {
return preg_replace( "/&amp;(#[0-9]+|[a-z]+);/i", "&$1;", @htmlspecialchars( $string, ENT_COMPAT, 'UTF-8' ) );
}


/**
* Simple version of helper_alternate_class for use by error api only.
* @access private
* @return string representing css class
*/
public static function error_alternate_class() {
static $errIndex = 1;

if( 1 == $errIndex++ % 2 ) {
return 'class="row-1"';
} else {
return 'class="row-2"';
}
}

public static function error_parameters( $args ) {
self::$parameters = $args;
}

public static function error_proceed_url( $url ) {
self::$proceedUrl = $url();
}

public static function error_handled() {
return self::$handled;
}
Expand Down
2 changes: 0 additions & 2 deletions application/core/access_api.php
Expand Up @@ -30,7 +30,6 @@
* @uses constant_inc.php
* @uses current_user_api.php
* @uses database_api.php
* @uses error_api.php
* @uses helper_api.php
* @uses lang_api.php
* @uses print_api.php
Expand All @@ -48,7 +47,6 @@
require_api( 'constant_inc.php' );
require_api( 'current_user_api.php' );
require_api( 'database_api.php' );
require_api( 'error_api.php' );
require_api( 'helper_api.php' );
require_api( 'lang_api.php' );
require_api( 'print_api.php' );
Expand Down
2 changes: 0 additions & 2 deletions application/core/authentication_api.php
Expand Up @@ -28,7 +28,6 @@
* @uses crypto_api.php
* @uses current_user_api.php
* @uses database_api.php
* @uses error_api.php
* @uses gpc_api.php
* @uses helper_api.php
* @uses html_api.php
Expand All @@ -50,7 +49,6 @@
require_api( 'crypto_api.php' );
require_api( 'current_user_api.php' );
require_api( 'database_api.php' );
require_api( 'error_api.php' );
require_api( 'gpc_api.php' );
require_api( 'helper_api.php' );
require_api( 'html_api.php' );
Expand Down
2 changes: 0 additions & 2 deletions application/core/category_api.php
Expand Up @@ -26,7 +26,6 @@
* @uses config_api.php
* @uses constant_inc.php
* @uses database_api.php
* @uses error_api.php
* @uses helper_api.php
* @uses history_api.php
* @uses lang_api.php
Expand All @@ -43,7 +42,6 @@
require_api( 'config_api.php' );
require_api( 'constant_inc.php' );
require_api( 'database_api.php' );
require_api( 'error_api.php' );
require_api( 'helper_api.php' );
require_api( 'history_api.php' );
require_api( 'lang_api.php' );
Expand Down
8 changes: 0 additions & 8 deletions application/core/config_api.php
Expand Up @@ -26,7 +26,6 @@
* @uses authentication_api.php
* @uses constant_inc.php
* @uses database_api.php
* @uses error_api.php
* @uses helper_api.php
* @uses utility_api.php
*/
Expand All @@ -36,7 +35,6 @@
require_api( 'authentication_api.php' );
require_api( 'constant_inc.php' );
require_api( 'database_api.php' );
require_api( 'error_api.php' );
require_api( 'helper_api.php' );
require_api( 'utility_api.php' );

Expand Down Expand Up @@ -86,9 +84,6 @@ function config_get( $p_option, $p_default = null, $p_user = null, $p_project =
}

if( $g_cache_db_table_exists ) {

# @@ debug @@ echo " lu db $p_option ";
# @@ debug @@ error_print_stack_trace();
# prepare the user's list
$t_users = array();
if( null === $p_user ) {
Expand Down Expand Up @@ -459,9 +454,6 @@ function config_delete( $p_option, $p_user = ALL_USERS, $p_project = ALL_PROJECT
return;
}

# @@ debug @@ echo "lu table=" . ( db_table_exists( 'config' ) ? "yes" : "no" );
# @@ debug @@ error_print_stack_trace();

$c_user = db_prepare_int( $p_user );
$c_project = db_prepare_int( $p_project );
$query = "DELETE FROM {config}
Expand Down
2 changes: 0 additions & 2 deletions application/core/custom_field_api.php
Expand Up @@ -30,7 +30,6 @@
* @uses constant_inc.php
* @uses database_api.php
* @uses email_api.php
* @uses error_api.php
* @uses helper_api.php
* @uses history_api.php
* @uses project_api.php
Expand All @@ -51,7 +50,6 @@
require_api( 'constant_inc.php' );
require_api( 'database_api.php' );
require_api( 'email_api.php' );
require_api( 'error_api.php' );
require_api( 'helper_api.php' );
require_api( 'history_api.php' );
require_api( 'project_api.php' );
Expand Down
2 changes: 0 additions & 2 deletions application/core/email_queue_api.php
Expand Up @@ -25,7 +25,6 @@
*
* @uses constant_api.php
* @uses database_api.php
* @uses error_api.php
* @uses lang_api.php
* @uses utility_api.php
*/
Expand All @@ -34,7 +33,6 @@

require_api( 'constant_inc.php' );
require_api( 'database_api.php' );
require_api( 'error_api.php' );
require_api( 'lang_api.php' );
require_api( 'utility_api.php' );

Expand Down
145 changes: 0 additions & 145 deletions application/core/error_api.php

This file was deleted.

13 changes: 0 additions & 13 deletions application/core/html_api.php
Expand Up @@ -63,7 +63,6 @@
* @uses constant_inc.php
* @uses current_user_api.php
* @uses database_api.php
* @uses error_api.php
* @uses event_api.php
* @uses file_api.php
* @uses filter_api.php
Expand All @@ -88,7 +87,6 @@
require_api( 'constant_inc.php' );
require_api( 'current_user_api.php' );
require_api( 'database_api.php' );
require_api( 'error_api.php' );
require_api( 'event_api.php' );
require_api( 'file_api.php' );
require_api( 'filter_api.php' );
Expand All @@ -109,9 +107,6 @@

$g_robots_meta = '';

# flag for error handler to skip header menus
$g_error_send_page_header = true;

$g_stylesheets_included = array();
$g_scripts_included = array();

Expand Down Expand Up @@ -237,11 +232,8 @@ function html_page_top2() {
* @return null
*/
function html_page_top2a() {
global $g_error_send_page_header;

html_head_end();
html_body_begin();
$g_error_send_page_header = false;
html_header();
html_top_banner();
}
Expand Down Expand Up @@ -378,18 +370,13 @@ function html_css_link( $p_filename ) {
* (6) Print an HTML meta tag to redirect to another page
* This function is optional and may be called by pages that need a redirect.
* $p_time is the number of seconds to wait before redirecting.
* If we have handled any errors on this page return false and don't redirect.
*
* @param string $p_url The page to redirect: has to be a relative path
* @param integer $p_time seconds to wait for before redirecting
* @param boolean $p_sanitize apply string_sanitize_url to passed url
* @return boolean
*/
function html_meta_redirect( $p_url, $p_time = null, $p_sanitize = true ) {
if( error_handled() ) {
return false;
}

if( null === $p_time ) {
$p_time = current_user_get_pref( 'redirect_delay' );
}
Expand Down

0 comments on commit c0827e0

Please sign in to comment.