📄 error.php
字号:
*
* @static
* @param object $error Exception object to handle
* @param array $options Handler options
* @return object The exception object
* @since 1.5
*
* @see raise()
*/
function & handleVerbose(& $error, $options)
{
$level_human = JError::translateErrorLevel($error->get('level'));
$info = $error->get('info');
if (isset ($_SERVER['HTTP_HOST'])) {
// output as html
echo "<br /><b>J$level_human</b>: ".$error->get('message')."<br />\n";
if ($info != null) {
echo " ".$info."<br />\n";
}
echo $error->getBacktrace(true);
} else {
// output as simple text
echo "J$level_human: ".$error->get('message')."\n";
if ($info != null) {
echo "\t".$info."\n";
}
}
return $error;
}
/**
* Die error handler
* - Echos the error message to output and then dies
*
* @static
* @param object $error Exception object to handle
* @param array $options Handler options
* @return object The exception object
* @since 1.5
*
* @see raise()
*/
function & handleDie(& $error, $options)
{
$level_human = JError::translateErrorLevel($error->get('level'));
if (isset ($_SERVER['HTTP_HOST'])) {
// output as html
die("<br /><b>J$level_human</b> ".$error->get('message')."<br />\n");
} else {
// output as simple text
if (defined('STDERR')) {
fwrite(STDERR, "J$level_human ".$error->get('message')."\n");
} else {
die("J$level_human ".$error->get('message')."\n");
}
}
return $error;
}
/**
* Message error handler
* - Enqueues the error message into the system queue
*
* @static
* @param object $error Exception object to handle
* @param array $options Handler options
* @return object The exception object
* @since 1.5
*
* @see raise()
*/
function & handleMessage(& $error, $options)
{
global $mainframe;
$type = ($error->get('level') == E_NOTICE) ? 'notice' : 'error';
$mainframe->enqueueMessage($error->get('message'), $type);
return $error;
}
/**
* Log error handler
* - Logs the error message to a system log file
*
* @static
* @param object $error Exception object to handle
* @param array $options Handler options
* @return object The exception object
* @since 1.5
*
* @see raise()
*/
function & handleLog(& $error, $options)
{
static $log;
if ($log == null) {
jimport('joomla.utilities.log');
$fileName = date('Y-m-d').'.error.log';
$options['format'] = "{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}";
$log = & JLog::getInstance($fileName, $options);
}
$entry['level'] = $error->get('level');
$entry['code'] = $error->get('code');
$entry['message'] = str_replace(array ("\r","\n"), array ('','\\n'), $error->get('message'));
$log->addEntry($entry);
return $error;
}
/**
* Trigger error handler
* - Triggers a PHP native error with the error message
*
* @static
* @param object $error Exception object to handle
* @param array $options Handler options
* @return object The exception object
* @since 1.5
*
* @see raise()
*/
function &handleTrigger( &$error, $options )
{
switch( $error->get('level') )
{
case E_NOTICE:
$level = E_USER_NOTICE;
break;
case E_WARNING:
$level = E_USER_WARNING;
break;
case E_NOTICE:
$level = E_NOTICE;
break;
default:
$level = E_USER_ERROR;
break;
}
trigger_error( $error->get('message'), $level );
return $error;
}
/**
* Callback error handler
* - Send the error object to a callback method for error handling
*
* @static
* @param object $error Exception object to handle
* @param array $options Handler options
* @return object The exception object
* @since 1.5
*
* @see raise()
*/
function &handleCallback( &$error, $options )
{
$result = call_user_func( $options, $error );
return $result;
}
/**
* Display a custom error page and exit gracefully
*
* @static
* @param object $error Exception object
* @return void
* @since 1.5
*/
function customErrorPage(& $error)
{
global $mainframe;
// Initialize variables
jimport('joomla.document.document');
$document = & JDocument::getInstance('error');
$config = & JFactory::getConfig();
// Get the current template from the application
$template = $mainframe->getTemplate();
// Push the error object into the document
$document->setError($error);
@ob_end_clean();
jimport('joomla.i18n.language');
$document->setTitle(JText::_('Error').': '.$error->code);
$data = $document->render(false, array (
'template' => $template,
'directory' => JPATH_THEMES,
'debug' => $config->getValue('config.debug')
));
JResponse::setBody($data);
echo JResponse::toString();
$mainframe->close(0);
}
}
/**
* Joomla! Exception object.
*
* This class is inspired in design and concept by patError <http://www.php-tools.net>
*
* patError contributors include:
* - gERD Schaufelberger <gerd@php-tools.net>
* - Sebastian Mordziol <argh@php-tools.net>
* - Stephan Schmidt <scst@php-tools.net>
*
* @author Louis Landry <louis.landry@joomla.org>
* @package Joomla.Framework
* @subpackage Utilities
* @since 1.5
*/
class JException extends JObject
{
/**
* Error level
* @var string
*/
var $level = null;
/**
* Error code
* @var string
*/
var $code = null;
/**
* Error message
* @var string
*/
var $message = null;
/**
* Additional info about the error relevant to the developer
* - e.g. if a database connect fails, the dsn used
* @var string
*/
var $info = '';
/**
* Name of the file the error occurred in [Available if backtrace is enabled]
* @var string
*/
var $file = null;
/**
* Line number the error occurred in [Available if backtrace is enabled]
* @var int
*/
var $line = 0;
/**
* Name of the method the error occurred in [Available if backtrace is enabled]
* @var string
*/
var $function = null;
/**
* Name of the class the error occurred in [Available if backtrace is enabled]
* @var string
*/
var $class = null;
/**
* Error type
* @var string
*/
var $type = null;
/**
* Arguments recieved by the method the error occurred in [Available if backtrace is enabled]
* @var array
*/
var $args = array();
/**
* Backtrace information
* @var mixed
*/
var $backtrace = false;
/**
* Constructor
* - used to set up the error with all needed error details.
*
* @access protected
* @param int $level The error level (use the PHP constants E_ALL, E_NOTICE etc.).
* @param string $code The error code from the application
* @param string $msg The error message
* @param string $info Optional: The additional error information.
*/
function __construct( $level, $code, $msg, $info = null, $backtrace = false )
{
$this->level = $level;
$this->code = $code;
$this->message = $msg;
if( $info != null ) {
$this->info = $info;
}
if( $backtrace && function_exists( 'debug_backtrace' ) ) {
$this->backtrace = debug_backtrace();
for( $i = count( $this->backtrace ) - 1; $i >= 0; --$i )
{
++$i;
if( isset( $this->backtrace[$i]['file'] ) )
$this->file = $this->backtrace[$i]['file'];
if( isset( $this->backtrace[$i]['line'] ) )
$this->line = $this->backtrace[$i]['line'];
if( isset( $this->backtrace[$i]['class'] ) )
$this->class = $this->backtrace[$i]['class'];
if( isset( $this->backtrace[$i]['function'] ) )
$this->function = $this->backtrace[$i]['function'];
if( isset( $this->backtrace[$i]['type'] ) )
$this->type = $this->backtrace[$i]['type'];
$this->args = false;
if( isset( $this->backtrace[$i]['args'] ) ) {
$this->args = $this->backtrace[$i]['args'];
}
break;
}
}
}
/**
* Method to get the backtrace information for an exception object
*
* @access public
* @return array backtrace
* @since 1.5
*/
function getBacktrace( $formatted=false )
{
if (isset( $this->backtrace )) {
$trace = &$this->backtrace;
} else {
$trace = function_exists( 'debug_backtrace' ) ? debug_backtrace() : null;
}
if ($formatted && is_array( $trace ))
{
$result = '';
foreach ($trace as $back)
{
if (isset($back['file']) && strpos($back['file'], 'error.php') === false) {
$result .= '<br />'.$back['file'].':'.$back['line'];
}
}
return $result;
}
return $this->backtrace;
}
/**
* Returns to error message
*
* @access public
* @return string Error message
* @since 1.5
*/
function toString()
{
return $this->message;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -