📄 error.php
字号:
<?php/** * @version $Id: error.php 10871 2008-08-30 07:30:33Z willebil $ * @package Joomla.Framework * @subpackage Error * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. * @license GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */// Check to ensure this file is within the rest of the frameworkdefined('JPATH_BASE') or die();// Error Definition: Illegal Optionsdefine( 'JERROR_ILLEGAL_OPTIONS', 1 );// Error Definition: Callback does not existdefine( 'JERROR_CALLBACK_NOT_CALLABLE', 2 );// Error Definition: Illegal Handlerdefine( 'JERROR_ILLEGAL_MODE', 3 );/* * JError exception stack */$GLOBALS['_JERROR_STACK'] = array();/* * Default available error levels */$GLOBALS['_JERROR_LEVELS'] = array( E_NOTICE => 'Notice', E_WARNING => 'Warning', E_ERROR => 'Error');/* * Default error handlers */$GLOBALS['_JERROR_HANDLERS'] = array( E_NOTICE => array( 'mode' => 'message' ), E_WARNING => array( 'mode' => 'message' ), E_ERROR => array( 'mode' => 'callback', 'options' => array('JError','customErrorPage') ));/** * Error Handling Class * * This class is inspired in design and concept by patErrorManager <http://www.php-tools.net> * * patErrorManager contributors include: * - gERD Schaufelberger <gerd@php-tools.net> * - Sebastian Mordziol <argh@php-tools.net> * - Stephan Schmidt <scst@php-tools.net> * * @static * @package Joomla.Framework * @subpackage Error * @since 1.5 */class JError{ /** * Method to determine if a value is an exception object. This check supports both JException and PHP5 Exception objects * * @static * @access public * @param mixed &$object Object to check * @return boolean True if argument is an exception, false otherwise. * @since 1.5 */ function isError(& $object) { if (!is_object($object)) { return false; } // supports PHP 5 exception handling return is_a($object, 'JException') || is_a($object, 'JError') || is_a($object, 'Exception'); } /** * Method for retrieving the last exception object in the error stack * * @static * @access public * @return mixed Last exception object in the error stack or boolean false if none exist * @since 1.5 */ function & getError($unset = false) { if (!isset($GLOBALS['_JERROR_STACK'][0])) { $false = false; return $false; } if ($unset) { $error = array_shift($GLOBALS['_JERROR_STACK']); } else { $error = &$GLOBALS['_JERROR_STACK'][0]; } return $error; } /** * Method for retrieving the exception stack * * @static * @access public * @return array Chronological array of errors that have been stored during script execution * @since 1.5 */ function & getErrors() { return $GLOBALS['_JERROR_STACK']; } /** * Create a new JException object given the passed arguments * * @static * @param int $level The error level - use any of PHP's own error levels for this: E_ERROR, E_WARNING, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE. * @param string $code The application-internal error code for this error * @param string $msg The error message, which may also be shown the user if need be. * @param mixed $info Optional: Additional error information (usually only developer-relevant information that the user should never see, like a database DSN). * @return mixed The JException object * @since 1.5 * * @see JException */ function & raise($level, $code, $msg, $info = null, $backtrace = false) { jimport('joomla.error.exception'); // build error object $exception = new JException($msg, $code, $level, $info, $backtrace); // see what to do with this kind of error $handler = JError::getErrorHandling($level); $function = 'handle'.ucfirst($handler['mode']); if (is_callable(array('JError', $function))) { $reference =& JError::$function ($exception, (isset($handler['options'])) ? $handler['options'] : array()); } else { // This is required to prevent a very unhelpful white-screen-of-death jexit( 'JError::raise -> Static method JError::' . $function . ' does not exist.' . ' Contact a developer to debug' . '<br /><strong>Error was</strong> ' . '<br />' . $exception->getMessage() ); } //store and return the error $GLOBALS['_JERROR_STACK'][] =& $reference; return $reference; } /** * Wrapper method for the {@link raise()} method with predefined error level of E_ERROR and backtrace set to true. * * @static * @param string $code The application-internal error code for this error * @param string $msg The error message, which may also be shown the user if need be. * @param mixed $info Optional: Additional error information (usually only developer-relevant information that the user should never see, like a database DSN). * @return object $error The configured JError object * @since 1.5 */ function & raiseError($code, $msg, $info = null) { $reference = & JError::raise(E_ERROR, $code, $msg, $info, true); return $reference; } /** * Wrapper method for the {@link raise()} method with predefined error level of E_WARNING and backtrace set to false. * * @static * @param string $code The application-internal error code for this error * @param string $msg The error message, which may also be shown the user if need be. * @param mixed $info Optional: Additional error information (usually only developer-relevant information that the user should never see, like a database DSN). * @return object $error The configured JError object * @since 1.5 */ function & raiseWarning($code, $msg, $info = null) { $reference = & JError::raise(E_WARNING, $code, $msg, $info); return $reference; } /** * Wrapper method for the {@link raise()} method with predefined error level of E_NOTICE and backtrace set to false. * * @static * @param string $code The application-internal error code for this error * @param string $msg The error message, which may also be shown the user if need be. * @param mixed $info Optional: Additional error information (usually only developer-relevant information that the user should never see, like a database DSN). * @return object $error The configured JError object * @since 1.5 */ function & raiseNotice($code, $msg, $info = null) { $reference = & JError::raise(E_NOTICE, $code, $msg, $info); return $reference; } /** * Method to get the current error handler settings for a specified error level. * * @static * @param int $level The error level to retrieve. This can be any of PHP's own error levels, e.g. E_ALL, E_NOTICE... * @return array All error handling details * @since 1.5 */ function getErrorHandling( $level ) { return $GLOBALS['_JERROR_HANDLERS'][$level]; } /** * Method to set the way the JError will handle different error levels. Use this if you want to override the default settings. * * Error handling modes: * - ignore * - echo * - verbose * - die * - message * - log * - callback * * You may also set the error handling for several modes at once using PHP's bit operations. * Examples: * - E_ALL = Set the handling for all levels * - E_ERROR | E_WARNING = Set the handling for errors and warnings * - E_ALL ^ E_ERROR = Set the handling for all levels except errors * * @static * @param int $level The error level for which to set the error handling * @param string $mode The mode to use for the error handling. * @param mixed $options Optional: Any options needed for the given mode. * @return mixed True on success, or a JException object if failed. * @since 1.5 */ function setErrorHandling($level, $mode, $options = null) { $levels = $GLOBALS['_JERROR_LEVELS']; $function = 'handle'.ucfirst($mode); if (!is_callable(array ('JError',$function))) { return JError::raiseError(E_ERROR, 'JError:'.JERROR_ILLEGAL_MODE, 'Error Handling mode is not known', 'Mode: '.$mode.' is not implemented.'); } foreach ($levels as $eLevel => $eTitle) { if (($level & $eLevel) != $eLevel) { continue; } // set callback options if ($mode == 'callback') { if (!is_array($options)) { return JError::raiseError(E_ERROR, 'JError:'.JERROR_ILLEGAL_OPTIONS, 'Options for callback not valid'); } if (!is_callable($options)) { $tmp = array ('GLOBAL'); if (is_array($options)) { $tmp[0] = $options[0]; $tmp[1] = $options[1]; } else { $tmp[1] = $options; } return JError::raiseError(E_ERROR, 'JError:'.JERROR_CALLBACK_NOT_CALLABLE, 'Function is not callable', 'Function:'.$tmp[1].' scope '.$tmp[0].'.'); } } // save settings $GLOBALS['_JERROR_HANDLERS'][$eLevel] = array ('mode' => $mode); if ($options != null) { $GLOBALS['_JERROR_HANDLERS'][$eLevel]['options'] = $options; } } return true; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -