/**
     * Stops PHP execution : die() if some critical error appeared
     * This method is taken from the great ameos_formidable extension.
     *
     * @param	string		$msg: the error message
     * @return	void
     */
    public static function mayday($msg, $extKey = '')
    {
        tx_rnbase::load('tx_rnbase_util_Logger');
        tx_rnbase::load('tx_rnbase_util_Debug');
        tx_rnbase_util_Logger::fatal($msg, $extKey ? $extKey : 'rn_base');
        $aTrace = debug_backtrace();
        $aLocation = array_shift($aTrace);
        $aTrace1 = array_shift($aTrace);
        $aTrace2 = array_shift($aTrace);
        $aTrace3 = array_shift($aTrace);
        $aTrace4 = array_shift($aTrace);
        $aDebug = array();
        $aDebug[] = '<h2 id="backtracetitle">Call stack</h2>';
        $aDebug[] = '<div class="backtrace">';
        $aDebug[] = '<span class="notice"><b>Call 0: </b>' . str_replace(PATH_site, '/', $aLocation['file']) . ':' . $aLocation['line'] . ' | <b>' . $aTrace1['class'] . $aTrace1['type'] . $aTrace1['function'] . '</b></span><br/>With parameters: ' . (!empty($aTrace1['args']) ? self::viewMixed($aTrace1['args']) : ' no parameters');
        $aDebug[] = '<hr/>';
        $aDebug[] = '<span class="notice"><b>Call -1: </b>' . str_replace(PATH_site, '/', $aTrace1['file']) . ':' . $aTrace1['line'] . ' | <b>' . $aTrace2['class'] . $aTrace2['type'] . $aTrace2['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace2['args']) ? self::viewMixed($aTrace2['args']) : ' no parameters');
        $aDebug[] = '<hr/>';
        $aDebug[] = '<span class="notice"><b>Call -2: </b>' . str_replace(PATH_site, '/', $aTrace2['file']) . ':' . $aTrace2['line'] . ' | <b>' . $aTrace3['class'] . $aTrace3['type'] . $aTrace3['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace3['args']) ? self::viewMixed($aTrace3['args']) : ' no parameters');
        $aDebug[] = '<hr/>';
        $aDebug[] = '<span class="notice"><b>Call -3: </b>' . str_replace(PATH_site, '/', $aTrace3['file']) . ':' . $aTrace3['line'] . ' | <b>' . $aTrace4['class'] . $aTrace4['type'] . $aTrace4['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace4['args']) ? self::viewMixed($aTrace4['args']) : ' no parameters');
        $aDebug[] = '<hr/>';
        if ($debugTrail = tx_rnbase_util_Debug::getDebugTrail()) {
            $aDebug[] = '<span class="notice">' . $debugTrail . '</span>';
            $aDebug[] = '<hr/>';
        }
        $aDebug[] = '</div>';
        if (intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'forceException4Mayday'))) {
            throw tx_rnbase::makeInstance('tx_rnbase_util_Exception', $msg, 0, array('Info' => $aDebug));
        }
        $aDebug[] = '<br/>';
        $sContent = '<h1 id="title">Mayday</h1>';
        $sContent .= '<div id="errormessage">' . $msg . '</div>';
        $sContent .= '<hr />';
        $verbose = intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'verboseMayday'));
        if ($verbose) {
            $sContent .= implode('', $aDebug);
        }
        $sPage = <<<MAYDAYPAGE
<!DOCTYPE html
\tPUBLIC '-//W3C//DTD XHTML 1.1//EN'
\t'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
\t<head>
\t\t<title>{$extKey}::Mayday</title>
\t\t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
\t\t<meta name="robots" content="noindex, nofollow" />
\t\t<style type="text/css">

\t\t\t#title {
\t\t\t\tcolor: red;
\t\t\t\tfont-family: Verdana;
\t\t\t}

\t\t\t#errormessage {
\t\t\t\tborder: 2px solid red;
\t\t\t\tpadding: 10px;
\t\t\t\tcolor: white;
\t\t\t\tbackground-color: red;
\t\t\t\tfont-family: Verdana;
\t\t\t\tfont-size: 12px;
\t\t\t}

\t\t\t.notice {
\t\t\t\tfont-family: Verdana;
\t\t\t\tfont-size: 9px;
\t\t\t\tfont-style: italic;
\t\t\t}

\t\t\t#backtracetitle {
\t\t\t}

\t\t\t.backtrace {
\t\t\t\tbackground-color: #FFFFCC;
\t\t\t}

\t\t\tHR {
\t\t\t\tborder: 1px solid silver;
\t\t\t}
\t\t</style>
\t</head>
\t<body>
\t\t{$sContent}
\t</body>
</html>

MAYDAYPAGE;
        $dieOnMayday = intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'dieOnMayday'));
        if ($dieOnMayday) {
            die($sPage);
        } else {
            echo $sPage;
        }
    }
 /**
  * @return 	array
  */
 public static function getDebugBacktrace()
 {
     tx_rnbase::load('tx_rnbase_util_Debug');
     return tx_rnbase_util_Debug::getDebugTrail();
 }