⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errorstack.php

📁 This is the script which used on 10minutemail.com for temporary email.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
     */    function setMessageCallback($msgCallback)    {        if (!$msgCallback) {            $this->_msgCallback = array(&$this, 'getErrorMessage');        } else {            if (is_callable($msgCallback)) {                $this->_msgCallback = $msgCallback;            }        }    }        /**     * Get an error code => error message mapping callback     *      * This method returns the current callback that can be used to generate error     * messages     * @return array|string|false Callback function/method or false if none     */    function getMessageCallback()    {        return $this->_msgCallback;    }        /**     * Sets a default callback to be used by all error stacks     *      * This method sets the callback that can be used to generate error     * messages for a singleton     * @param array|string Callback function/method     * @param string Package name, or false for all packages     * @static     */    function setDefaultCallback($callback = false, $package = false)    {        if (!is_callable($callback)) {            $callback = false;        }        $package = $package ? $package : '*';        $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$package] = $callback;    }        /**     * Set a callback that generates context information (location of error) for an error stack     *      * This method sets the callback that can be used to generate context     * information for an error.  Passing in NULL will disable context generation     * and remove the expensive call to debug_backtrace()     * @param array|string|null Callback function/method     */    function setContextCallback($contextCallback)    {        if ($contextCallback === null) {            return $this->_contextCallback = false;        }        if (!$contextCallback) {            $this->_contextCallback = array(&$this, 'getFileLine');        } else {            if (is_callable($contextCallback)) {                $this->_contextCallback = $contextCallback;            }        }    }        /**     * Set an error Callback     * If set to a valid callback, this will be called every time an error     * is pushed onto the stack.  The return value will be used to determine     * whether to allow an error to be pushed or logged.     *      * The return value must be one of the ERRORSTACK_* constants.     *      * This functionality can be used to emulate PEAR's pushErrorHandling, and     * the PEAR_ERROR_CALLBACK mode, without affecting the integrity of     * the error stack or logging     * @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG     * @see popCallback()     * @param string|array $cb     */    function pushCallback($cb)    {        array_push($this->_errorCallback, $cb);    }        /**     * Remove a callback from the error callback stack     * @see pushCallback()     * @return array|string|false     */    function popCallback()    {        if (!count($this->_errorCallback)) {            return false;        }        return array_pop($this->_errorCallback);    }        /**     * Set a temporary overriding error callback for every package error stack     *     * Use this to temporarily disable all existing callbacks (can be used     * to emulate the @ operator, for instance)     * @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG     * @see staticPopCallback(), pushCallback()     * @param string|array $cb     * @static     */    function staticPushCallback($cb)    {        array_push($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'], $cb);    }        /**     * Remove a temporary overriding error callback     * @see staticPushCallback()     * @return array|string|false     * @static     */    function staticPopCallback()    {        $ret = array_pop($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK']);        if (!is_array($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'])) {            $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array();        }        return $ret;    }        /**     * Add an error to the stack     *      * If the message generator exists, it is called with 2 parameters.     *  - the current Error Stack object     *  - an array that is in the same format as an error.  Available indices     *    are 'code', 'package', 'time', 'params', 'level', and 'context'     *      * Next, if the error should contain context information, this is     * handled by the context grabbing method.     * Finally, the error is pushed onto the proper error stack     * @param int    $code      Package-specific error code     * @param string $level     Error level.  This is NOT spell-checked     * @param array  $params    associative array of error parameters     * @param string $msg       Error message, or a portion of it if the message     *                          is to be generated     * @param array  $repackage If this error re-packages an error pushed by     *                          another package, place the array returned from     *                          {@link pop()} in this parameter     * @param array  $backtrace Protected parameter: use this to pass in the     *                          {@link debug_backtrace()} that should be used     *                          to find error context     * @return PEAR_Error|array if compatibility mode is on, a PEAR_Error is also     * thrown.  If a PEAR_Error is returned, the userinfo     * property is set to the following array:     *      * <code>     * array(     *    'code' => $code,     *    'params' => $params,     *    'package' => $this->_package,     *    'level' => $level,     *    'time' => time(),     *    'context' => $context,     *    'message' => $msg,     * //['repackage' => $err] repackaged error array/Exception class     * );     * </code>     *      * Normally, the previous array is returned.     */    function push($code, $level = 'error', $params = array(), $msg = false,                  $repackage = false, $backtrace = false)    {        $context = false;        // grab error context        if ($this->_contextCallback) {            if (!$backtrace) {                $backtrace = debug_backtrace();            }            $context = call_user_func($this->_contextCallback, $code, $params, $backtrace);        }                // save error        $time = explode(' ', microtime());        $time = $time[1] + $time[0];        $err = array(                'code' => $code,                'params' => $params,                'package' => $this->_package,                'level' => $level,                'time' => $time,                'context' => $context,                'message' => $msg,               );        if ($repackage) {            $err['repackage'] = $repackage;        }        // set up the error message, if necessary        if ($this->_msgCallback) {            $msg = call_user_func_array($this->_msgCallback,                                        array(&$this, $err));            $err['message'] = $msg;        }                $push = $log = true;        $die = false;        // try the overriding callback first        $callback = $this->staticPopCallback();        if ($callback) {            $this->staticPushCallback($callback);        }        if (!is_callable($callback)) {            // try the local callback next            $callback = $this->popCallback();            if (is_callable($callback)) {                $this->pushCallback($callback);            } else {                // try the default callback                $callback = isset($GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$this->_package]) ?                    $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$this->_package] :                    $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK']['*'];            }        }        if (is_callable($callback)) {            switch(call_user_func($callback, $err)){            	case PEAR_ERRORSTACK_IGNORE:             		return $err;        		break;            	case PEAR_ERRORSTACK_PUSH:             		$log = false;        		break;            	case PEAR_ERRORSTACK_LOG:             		$push = false;        		break;            	case PEAR_ERRORSTACK_DIE:             		$die = true;        		break;                // anything else returned has the same effect as pushandlog            }        }        if ($push) {            array_unshift($this->_errors, $err);            if (!isset($this->_errorsByLevel[$err['level']])) {                $this->_errorsByLevel[$err['level']] = array();            }            $this->_errorsByLevel[$err['level']][] = &$this->_errors[0];        }        if ($log) {            if ($this->_logger || $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER']) {                $this->_log($err);            }        }        if ($die) {            die();        }        if ($this->_compat && $push) {            return $this->raiseError($msg, $code, null, null, $err);        }        return $err;    }        /**     * Static version of {@link push()}     *      * @param string $package   Package name this error belongs to     * @param int    $code      Package-specific error code     * @param string $level     Error level.  This is NOT spell-checked     * @param array  $params    associative array of error parameters     * @param string $msg       Error message, or a portion of it if the message     *                          is to be generated     * @param array  $repackage If this error re-packages an error pushed by     *                          another package, place the array returned from     *                          {@link pop()} in this parameter     * @param array  $backtrace Protected parameter: use this to pass in the     *                          {@link debug_backtrace()} that should be used     *                          to find error context     * @return PEAR_Error|array if compatibility mode is on, a PEAR_Error is also     *                          thrown.  see docs for {@link push()}     * @static     */    function staticPush($package, $code, $level = 'error', $params = array(),                        $msg = false, $repackage = false, $backtrace = false)    {        $s = &PEAR_ErrorStack::singleton($package);        if ($s->_contextCallback) {            if (!$backtrace) {                if (function_exists('debug_backtrace')) {                    $backtrace = debug_backtrace();                }            }        }        return $s->push($code, $level, $params, $msg, $repackage, $backtrace);    }        /**     * Log an error using PEAR::Log     * @param array $err Error array     * @param array $levels Error level => Log constant map     * @access protected     */    function _log($err)    {        if ($this->_logger) {            $logger = &$this->_logger;        } else {            $logger = &$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'];        }        if (is_a($logger, 'Log')) {            $levels = array(                'exception' => PEAR_LOG_CRIT,                'alert' => PEAR_LOG_ALERT,                'critical' => PEAR_LOG_CRIT,                'error' => PEAR_LOG_ERR,                'warning' => PEAR_LOG_WARNING,                'notice' => PEAR_LOG_NOTICE,                'info' => PEAR_LOG_INFO,                'debug' => PEAR_LOG_DEBUG);            if (isset($levels[$err['level']])) {                $level = $levels[$err['level']];            } else {                $level = PEAR_LOG_INFO;            }            $logger->log($err['message'], $level, $err);        } else { // support non-standard logs            call_user_func($logger, $err);        }    }        /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -