<?php
/**
 * custom patErrorManager handler for the callback error handling mode
 *
 * Provides the pat-teams favourite error handlers.
 *
 * $Id: patErrorHandlerDebug.php,v 1.1 2004/02/10 21:58:18 gerd Exp $
 *
 * @access		public
 * @package		patError
 * @subpackage	Debug
 */
 
/**
 * custom patErrorManager handler for the callback error handling mode
 *
 * @package		patErrorManager
 * @subpackage	Debug
 * @author		gERD Schaufelberger <gerd@php-tools.net>
 * @author		Stephan Schmidt <schst@php-tools.net>
 * @version		0.1
 * @license		LGPL
 * @link		http://www.php-tools.net
 */
class   patErrorHandlerDebug
{
	/**
	* niceDie - outputs a nicely formatted version of the traditional die()
	*
	* @static
	* @access	public
	* @param	string	$error	The error message to display
	*/
    function niceDie( $error )
    {
		echo	'<html>
					<body bgcolor="#ffffff" text="#000000">
					<div style="padding:20px;">
						<div style="font-family:tahoma;font-size:12px;font-weight:bold;margin-bottom:10px;">critical Error encountered [patDebugErrorHandler]</div>
						<table cellpadding="0" cellspacing="0" border="0">
							<tr valign="top">
								<td>Error details</td>
								<td>&nbsp;:&nbsp;</td>
								<td>
									<pre>';
										print_r( $error );
		echo	'					</pre>
								</td>
							</tr>
						</table>
					</div>
					</body>
					</html>';
					
		exit();
    }

   /**
	* error handler that outputs nice debugging HTML
	*
	* Displays:
	* - Error level
	* - Error Message
	* - Error info
	* - Error file
	* - Error line
	* - plus the call stack that lead to the error
	*
	* The output has been inspired by Derick Rethan's xDebug.
	*
	* @author	Stephan Schmidt <schst@php-tools.net>
	* @access	public
	* @static
	* @param	object		error object
	* @return	object		error object
	* @todo		console output (no HTML)
	*/
	function &schstDebug( &$error )
	{
		echo	'<div style="backgound-color:#ffffff;">';
		printf(
				"<strong>%s:</strong> %s (Userinfo: %s) in %s on line %s<br />",
				patErrorManager::translateErrorLevel( $error->getLevel() ),
				$error->getMessage(),
				$error->getInfo(),
				$error->getFile(),
				$error->getLine()
			);

		$backtrace	=	$error->getBacktrace();
		if( is_array( $backtrace ) )
		{
			$j	=	1;
			echo	'<table border="1" cellpadding="2" cellspacing="1" style="border-width:1px; border-style:solid; border-color:#000000;">';
			echo	'	<tr>';
			echo	'		<td colspan="3" align="center"><strong>Call stack</strong></td>';
			echo	'	</tr>';
			echo	'	<tr>';
			echo	'		<td><strong>#</strong></td>';
			echo	'		<td><strong>Function</strong></td>';
			echo	'		<td><strong>Location</strong></td>';
			echo	'	</tr>';
			for( $i = count( $backtrace )-1; $i >= 0 ; $i-- )
			{
				echo	'	<tr>';
				echo	"		<td>{$j}</td>";
				if( isset( $backtrace[$i]['class'] ) )
				{
					echo	"	<td>{$backtrace[$i]['class']}{$backtrace[$i]['type']}{$backtrace[$i]['function']}()</td>";
				}
				else
				{
					echo	"	<td>{$backtrace[$i]['function']}()</td>";
				}
				if( isset( $backtrace[$i]['file'] ) )
				{
					echo	"		<td>{$backtrace[$i]['file']}:{$backtrace[$i]['line']}</td>";
				}
				else
				{
					echo	"		<td>&nbsp;</td>";
				}
				echo	'	</tr>';
				$j++;
			}
			echo	'</table>';
		}
		echo	'</div>';
		
		$level	=	$error->getLevel();
		
		if( $level != E_ERROR )
			return	$error;
			
		exit();
	}
}
?>