home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phptriad / phptriad2-2-1.exe / php / pear / PEAR.php < prev    next >
PHP Script  |  2001-11-13  |  25KB  |  796 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2001 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Sterling Hughes <sterling@php.net>                          |
  17. // |          Stig Bakken <ssb@fast.no>                                   |
  18. // |          Tomas V.V.Cox <cox@idecnet.com>                             |
  19. // |                                                                      |
  20. // +----------------------------------------------------------------------+
  21. //
  22. // $Id: PEAR.php,v 1.13.2.4 2001/11/13 01:26:39 ssb Exp $
  23. //
  24.  
  25. define('PEAR_ERROR_RETURN',   1);
  26. define('PEAR_ERROR_PRINT',    2);
  27. define('PEAR_ERROR_TRIGGER',  4);
  28. define('PEAR_ERROR_DIE',      8);
  29. define('PEAR_ERROR_CALLBACK', 16);
  30.  
  31. if (substr(PHP_OS, 0, 3) == 'WIN') {
  32.     define('OS_WINDOWS', true);
  33.     define('OS_UNIX',    false);
  34.     define('PEAR_OS',    'Windows');
  35. } else {
  36.     define('OS_WINDOWS', false);
  37.     define('OS_UNIX',    true);
  38.     define('PEAR_OS',    'Unix'); // blatant assumption
  39. }
  40.  
  41. $GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
  42. $GLOBALS['_PEAR_default_error_options']  = E_USER_NOTICE;
  43. $GLOBALS['_PEAR_default_error_callback'] = '';
  44. $GLOBALS['_PEAR_destructor_object_list'] = array();
  45.  
  46. //
  47. // Tests needed: - PEAR inheritance
  48. //               - destructors
  49. //
  50.  
  51. /**
  52.  * Base class for other PEAR classes.  Provides rudimentary
  53.  * emulation of destructors.
  54.  *
  55.  * If you want a destructor in your class, inherit PEAR and make a
  56.  * destructor method called _yourclassname (same name as the
  57.  * constructor, but with a "_" prefix).  Also, in your constructor you
  58.  * have to call the PEAR constructor: $this->PEAR();.
  59.  * The destructor method will be called without parameters.  Note that
  60.  * at in some SAPI implementations (such as Apache), any output during
  61.  * the request shutdown (in which destructors are called) seems to be
  62.  * discarded.  If you need to get any debug information from your
  63.  * destructor, use error_log(), syslog() or something similar.
  64.  *
  65.  * @since PHP 4.0.2
  66.  * @author Stig Bakken <ssb@fast.no>
  67.  */
  68. class PEAR
  69. {
  70.     // {{{ properties
  71.  
  72.     /**
  73.      * Whether to enable internal debug messages.
  74.      *
  75.      * @var     bool
  76.      * @access  private
  77.      */
  78.     var $_debug = false;
  79.  
  80.     /**
  81.      * Default error mode for this object.
  82.      *
  83.      * @var     int
  84.      * @access  private
  85.      */
  86.     var $_default_error_mode = null;
  87.  
  88.     /**
  89.      * Default error options used for this object when error mode
  90.      * is PEAR_ERROR_TRIGGER.
  91.      *
  92.      * @var     int
  93.      * @access  private
  94.      */
  95.     var $_default_error_options = null;
  96.  
  97.     /**
  98.      * Default error handler (callback) for this object, if error mode is
  99.      * PEAR_ERROR_CALLBACK.
  100.      *
  101.      * @var     string
  102.      * @access  private
  103.      */
  104.     var $_default_error_handler = '';
  105.  
  106.     /**
  107.      * Which class to use for error objects.
  108.      *
  109.      * @var     string
  110.      * @access  private
  111.      */
  112.     var $_error_class = 'PEAR_Error';
  113.  
  114.     /**
  115.      * An array of expected errors.
  116.      *
  117.      * @var     array
  118.      * @access  private
  119.      */
  120.     var $_expected_errors = array();
  121.  
  122.     // }}}
  123.  
  124.     // {{{ constructor
  125.  
  126.     /**
  127.      * Constructor.  Registers this object in
  128.      * $_PEAR_destructor_object_list for destructor emulation if a
  129.      * destructor object exists.
  130.      *
  131.      * @param string      (optional) which class to use for error objects,
  132.      *                    defaults to PEAR_Error.
  133.      * @access public
  134.      * @return void
  135.      */
  136.     function PEAR($error_class = null)
  137.     {
  138.         $classname = get_class($this);
  139.         if ($this->_debug) {
  140.             print "PEAR constructor called, class=$classname\n";
  141.         }
  142.         if ($error_class !== null) {
  143.             $this->_error_class = $error_class;
  144.         }
  145.         while ($classname) {
  146.             $destructor = "_$classname";
  147.             if (method_exists($this, $destructor)) {
  148.                 global $_PEAR_destructor_object_list;
  149.                 $_PEAR_destructor_object_list[] = &$this;
  150.                 break;
  151.             } else {
  152.                 $classname = get_parent_class($classname);
  153.             }
  154.         }
  155.     }
  156.  
  157.     // }}}
  158.     // {{{ destructor
  159.  
  160.     /**
  161.      * Destructor (the emulated type of...).  Does nothing right now,
  162.      * but is included for forward compatibility, so subclass
  163.      * destructors should always call it.
  164.      *
  165.      * See the note in the class desciption about output from
  166.      * destructors.
  167.      *
  168.      * @access public
  169.      * @return void
  170.      */
  171.     function _PEAR() {
  172.         if ($this->_debug) {
  173.             printf("PEAR destructor called, class=%s\n", get_class($this));
  174.         }
  175.     }
  176.  
  177.     // }}}
  178.     // {{{ isError()
  179.  
  180.     /**
  181.      * Tell whether a value is a PEAR error.
  182.      *
  183.      * @param   mixed   the value to test
  184.      * @access  public
  185.      * @return  bool    true if parameter is an error
  186.      */
  187.     function isError($data) {
  188.         return (bool)(is_object($data) &&
  189.                       (get_class($data) == 'pear_error' ||
  190.                       is_subclass_of($data, 'pear_error')));
  191.     }
  192.  
  193.     // }}}
  194.     // {{{ setErrorHandling()
  195.  
  196.     /**
  197.      * Sets how errors generated by this DB object should be handled.
  198.      * Can be invoked both in objects and statically.  If called
  199.      * statically, setErrorHandling sets the default behaviour for all
  200.      * PEAR objects.  If called in an object, setErrorHandling sets
  201.      * the default behaviour for that object.
  202.      *
  203.      * @param int $mode
  204.      *        One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
  205.      *        PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or
  206.      *        PEAR_ERROR_CALLBACK.
  207.      *
  208.      * @param mixed $options
  209.      *        When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
  210.      *        of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
  211.      *
  212.      *        When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
  213.      *        to be the callback function or method.  A callback
  214.      *        function is a string with the name of the function, a
  215.      *        callback method is an array of two elements: the element
  216.      *        at index 0 is the object, and the element at index 1 is
  217.      *        the name of the method to call in the object.
  218.      *
  219.      *        When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
  220.      *        a printf format string used when printing the error
  221.      *        message.
  222.      *
  223.      * @access public
  224.      * @return void
  225.      * @see PEAR_ERROR_RETURN
  226.      * @see PEAR_ERROR_PRINT
  227.      * @see PEAR_ERROR_TRIGGER
  228.      * @see PEAR_ERROR_DIE
  229.      * @see PEAR_ERROR_CALLBACK
  230.      *
  231.      * @since PHP 4.0.5
  232.      */
  233.  
  234.     function setErrorHandling($mode = null, $options = null)
  235.     {
  236.         if (isset($this)) {
  237.             $setmode     = &$this->_default_error_mode;
  238.             $setoptions  = &$this->_default_error_options;
  239.             //$setcallback = &$this->_default_error_callback;
  240.         } else {
  241.             $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
  242.             $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
  243.             //$setcallback = &$GLOBALS['_PEAR_default_error_callback'];
  244.         }
  245.  
  246.         switch ($mode) {
  247.             case PEAR_ERROR_RETURN:
  248.             case PEAR_ERROR_PRINT:
  249.             case PEAR_ERROR_TRIGGER:
  250.             case PEAR_ERROR_DIE:
  251.             case null:
  252.                 $setmode = $mode;
  253.                 $setoptions = $options;
  254.                 break;
  255.  
  256.             case PEAR_ERROR_CALLBACK:
  257.                 $setmode = $mode;
  258.                 if ((is_string($options) && function_exists($options)) ||
  259.                     (is_array($options) && method_exists(@$options[0], @$options[1])))
  260.                 {
  261.                     $setoptions = $options;
  262.                 } else {
  263.                     trigger_error("invalid error callback", E_USER_WARNING);
  264.                 }
  265.                 break;
  266.  
  267.             default:
  268.                 trigger_error("invalid error mode", E_USER_WARNING);
  269.                 break;
  270.         }
  271.     }
  272.  
  273.     // }}}
  274.     // {{{ expectError()
  275.  
  276.     /**
  277.      * This method is used to tell which errors you expect to get.
  278.      * Expected errors are always returned with error mode
  279.      * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
  280.      * and this method pushes a new element onto it.  The list of
  281.      * expected errors are in effect until they are popped off the
  282.      * stack with the popExpect() method.
  283.      *
  284.      * @param mixed    a single error code or an array of error codes
  285.      *                 to expect
  286.      *
  287.      * @return int     the new depth of the "expected errors" stack
  288.      */
  289.     function expectError($code = "*")
  290.     {
  291.         if (is_array($code)) {
  292.             array_push($this->_expected_errors, $code);
  293.         } else {
  294.             array_push($this->_expected_errors, array($code));
  295.         }
  296.         return sizeof($this->_expected_errors);
  297.     }
  298.  
  299.     // }}}
  300.     // {{{ popExpect()
  301.  
  302.     /**
  303.      * This method pops one element off the expected error codes
  304.      * stack.
  305.      *
  306.      * @return array   the list of error codes that were popped
  307.      */
  308.     function popExpect()
  309.     {
  310.         return array_pop($this->_expected_errors);
  311.     }
  312.  
  313.     // }}}
  314.     // {{{ raiseError()
  315.  
  316.     /**
  317.      * This method is a wrapper that returns an instance of the
  318.      * configured error class with this object's default error
  319.      * handling applied.  If the $mode and $options parameters are not
  320.      * specified, the object's defaults are used.
  321.      *
  322.      * @param $message  a text error message or a PEAR error object
  323.      *
  324.      * @param $code     a numeric error code (it is up to your class
  325.      *                  to define these if you want to use codes)
  326.      *
  327.      * @param $mode     One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
  328.      *                  PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or
  329.      *                  PEAR_ERROR_CALLBACK.
  330.      *
  331.      * @param $options  If $mode is PEAR_ERROR_TRIGGER, this parameter
  332.      *                  specifies the PHP-internal error level (one of
  333.      *                  E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
  334.      *                  If $mode is PEAR_ERROR_CALLBACK, this
  335.      *                  parameter specifies the callback function or
  336.      *                  method.  In other error modes this parameter
  337.      *                  is ignored.
  338.      *
  339.      * @param $userinfo If you need to pass along for example debug
  340.      *                  information, this parameter is meant for that.
  341.      *
  342.      * @param $error_class The returned error object will be instantiated
  343.      *                  from this class, if specified.
  344.      *
  345.      * @param $skipmsg  If true, raiseError will only pass error codes,
  346.      *                  the error message parameter will be dropped.
  347.      *
  348.      * @access public
  349.      * @return object   a PEAR error object
  350.      * @see PEAR::setErrorHandling
  351.      * @since PHP 4.0.5
  352.      */
  353.     function &raiseError($message = null,
  354.                          $code = null,
  355.                          $mode = null,
  356.                          $options = null,
  357.                          $userinfo = null,
  358.                          $error_class = null,
  359.                          $skipmsg = false)
  360.     {
  361.         // The error is yet a PEAR error object
  362.         if (is_object($message)) {
  363.             $code        = $message->getCode();
  364.             $userinfo    = $message->getUserInfo();
  365.             $error_class = $message->getType();
  366.             $message     = $message->getMessage();
  367.         }
  368.  
  369.         if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
  370.             if ($exp[0] == "*" ||
  371.                 (is_int(reset($exp)) && in_array($code, $exp)) ||
  372.                 (is_string(reset($exp)) && in_array($message, $exp))) {
  373.                 $mode = PEAR_ERROR_RETURN;
  374.             }
  375.         }
  376.  
  377.         if ($mode === null) {
  378.             if (isset($this) && isset($this->_default_error_mode)) {
  379.                 $mode = $this->_default_error_mode;
  380.             } else {
  381.                 $mode = $GLOBALS['_PEAR_default_error_mode'];
  382.             }
  383.         }
  384.  
  385.         if ($mode == PEAR_ERROR_TRIGGER && $options === null) {
  386.             if (isset($this)) {
  387.                 if (isset($this->_default_error_options)) {
  388.                     $options = $this->_default_error_options;
  389.                 }
  390.             } else {
  391.                 $options = $GLOBALS['_PEAR_default_error_options'];
  392.             }
  393.         }
  394.  
  395.         if ($mode == PEAR_ERROR_CALLBACK) {
  396.             if (!is_string($options) &&
  397.                 !(is_array($options) && sizeof($options) == 2 &&
  398.                   is_object($options[0]) && is_string($options[1])))
  399.             {
  400.                 if (isset($this) && isset($this->_default_error_options)) {
  401.                     $options = $this->_default_error_options;
  402.                 } else {
  403.                     $options = $GLOBALS['_PEAR_default_error_options'];
  404.                 }
  405.             }
  406.         } else {
  407.             if ($options === null) {
  408.                 if (isset($this)) {
  409.                     if (isset($this->_default_error_options)) {
  410.                         $options = $this->_default_error_options;
  411.                     }
  412.                 } else {
  413.                     $options = $GLOBALS['_PEAR_default_error_options'];
  414.                 }
  415.             }
  416.         }
  417.         if ($error_class !== null) {
  418.             $ec = $error_class;
  419.         } elseif (isset($this) && isset($this->_error_class)) {
  420.             $ec = $this->_error_class;
  421.         } else {
  422.             $ec = 'PEAR_Error';
  423.         }
  424.         if ($skipmsg) {
  425.             return new $ec($code, $mode, $options, $userinfo);
  426.         } else {
  427.             return new $ec($message, $code, $mode, $options, $userinfo);
  428.         }
  429.     }
  430.  
  431.     // }}}
  432.     // {{{ pushErrorHandling()
  433.  
  434.     /**
  435.     * Push a new error handler on top of the error handler options stack. With this
  436.     * you can easely override the actual error handler for some code and restore
  437.     * it later with popErrorHandling.
  438.     *
  439.     * @param $mode mixed (same as setErrorHandling)
  440.     * @param $options mixed (same as setErrorHandling)
  441.     *
  442.     * @return bool Always true
  443.     *
  444.     * @see PEAR::setErrorHandling
  445.     */
  446.     function pushErrorHandling($mode, $options = null)
  447.     {
  448.         $stack = &$GLOBALS['_PEAR_error_handler_stack'];
  449.         if (!is_array($stack)) {
  450.             if (isset($this)) {
  451.                 $def_mode = &$this->_default_error_mode;
  452.                 $def_options = &$this->_default_error_options;
  453.                 // XXX Used anywhere?
  454.                 //$def_callback = &$this->_default_error_callback;
  455.             } else {
  456.                 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
  457.                 $def_options = &$GLOBALS['_PEAR_default_error_options'];
  458.                 // XXX Used anywhere?
  459.                 //$def_callback = &$GLOBALS['_PEAR_default_error_callback'];
  460.             }
  461.             $stack = array();
  462.             $stack[] = array($def_mode, $def_options);
  463.         }
  464.  
  465.         if (isset($this)) {
  466.             $this->setErrorHandling($mode, $options);
  467.         } else {
  468.             PEAR::setErrorHandling($mode, $options);
  469.         }
  470.         $stack[] = array($mode, $options);
  471.         return true;
  472.     }
  473.  
  474.     // }}}
  475.     // {{{ popErrorHandling()
  476.  
  477.     /**
  478.     * Pop the last error handler used
  479.     *
  480.     * @return bool Always true
  481.     *
  482.     * @see PEAR::pushErrorHandling
  483.     */
  484.     function popErrorHandling()
  485.     {
  486.         $stack = &$GLOBALS['_PEAR_error_handler_stack'];
  487.         array_pop($stack);
  488.         list($mode, $options) = $stack[sizeof($stack) - 1];
  489.         if (isset($this)) {
  490.             $this->setErrorHandling($mode, $options);
  491.         } else {
  492.             PEAR::setErrorHandling($mode, $options);
  493.         }
  494.         return true;
  495.     }
  496.  
  497.     // }}}
  498. }
  499.  
  500. // {{{ _PEAR_call_destructors()
  501.  
  502. function _PEAR_call_destructors()
  503. {
  504.     global $_PEAR_destructor_object_list;
  505.     if (is_array($_PEAR_destructor_object_list) &&
  506.         sizeof($_PEAR_destructor_object_list))
  507.     {
  508.         reset($_PEAR_destructor_object_list);
  509.         while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
  510.             $classname = get_class($objref);
  511.             while ($classname) {
  512.                 $destructor = "_$classname";
  513.                 if (method_exists($objref, $destructor)) {
  514.                     $objref->$destructor();
  515.                     break;
  516.                 } else {
  517.                     $classname = get_parent_class($classname);
  518.                 }
  519.             }
  520.         }
  521.         // Empty the object list to ensure that destructors are
  522.         // not called more than once.
  523.         $_PEAR_destructor_object_list = array();
  524.     }
  525. }
  526.  
  527. // }}}
  528.  
  529. class PEAR_Error
  530. {
  531.     // {{{ properties
  532.  
  533.     var $error_message_prefix = '';
  534.     var $mode                 = PEAR_ERROR_RETURN;
  535.     var $level                = E_USER_NOTICE;
  536.     var $code                 = -1;
  537.     var $message              = '';
  538.     var $userinfo             = '';
  539.  
  540.     // Wait until we have a stack-groping function in PHP.
  541.     //var $file    = '';
  542.     //var $line    = 0;
  543.  
  544.  
  545.     // }}}
  546.     // {{{ constructor
  547.  
  548.     /**
  549.      * PEAR_Error constructor
  550.      *
  551.      * @param $message error message
  552.      *
  553.      * @param $code (optional) error code
  554.      *
  555.      * @param $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
  556.      * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER or
  557.      * PEAR_ERROR_CALLBACK
  558.      *
  559.      * @param $level (optional) error level, _OR_ in the case of
  560.      * PEAR_ERROR_CALLBACK, the callback function or object/method
  561.      * tuple.
  562.      *
  563.      * @access public
  564.      *
  565.      */
  566.     function PEAR_Error($message = 'unknown error', $code = null,
  567.                         $mode = null, $options = null, $userinfo = null)
  568.     {
  569.         if ($mode === null) {
  570.             $mode = PEAR_ERROR_RETURN;
  571.         }
  572.         $this->message   = $message;
  573.         $this->code      = $code;
  574.         $this->mode      = $mode;
  575.         $this->userinfo  = $userinfo;
  576.         if ($mode & PEAR_ERROR_CALLBACK) {
  577.             $this->level = E_USER_NOTICE;
  578.             $this->callback = $options;
  579.         } else {
  580.             if ($options === null) {
  581.                 $options = E_USER_NOTICE;
  582.             }
  583.             $this->level = $options;
  584.             $this->callback = null;
  585.         }
  586.         if ($this->mode & PEAR_ERROR_PRINT) {
  587.             if (is_null($options) || is_int($options)) {
  588.                 $format = "%s";
  589.             } else {
  590.                 $format = $options;
  591.             }
  592.             printf($format, $this->getMessage());
  593.         }
  594.         if ($this->mode & PEAR_ERROR_TRIGGER) {
  595.             trigger_error($this->getMessage(), $this->level);
  596.         }
  597.         if ($this->mode & PEAR_ERROR_DIE) {
  598.             $msg = $this->getMessage();
  599.             if (is_null($options) || is_int($options)) {
  600.                 $format = "%s";
  601.                 if (substr($msg, -1) != "\n") {
  602.                     $msg .= "\n";
  603.                 }
  604.             } else {
  605.                 $format = $options;
  606.             }
  607.             die(sprintf($format, $msg));
  608.         }
  609.         if ($this->mode & PEAR_ERROR_CALLBACK) {
  610.             if (is_string($this->callback) && strlen($this->callback)) {
  611.                 call_user_func($this->callback, $this);
  612.             } elseif (is_array($this->callback) &&
  613.                       sizeof($this->callback) == 2 &&
  614.                       is_object($this->callback[0]) &&
  615.                       is_string($this->callback[1]) &&
  616.                       strlen($this->callback[1])) {
  617.                       @call_user_method($this->callback[1], $this->callback[0],
  618.                                  $this);
  619.             }
  620.         }
  621.     }
  622.  
  623.     // }}}
  624.     // {{{ getMode()
  625.  
  626.     /**
  627.      * Get the error mode from an error object.
  628.      *
  629.      * @return int error mode
  630.      * @access public
  631.      */
  632.     function getMode() {
  633.         return $this->mode;
  634.     }
  635.  
  636.     // }}}
  637.     // {{{ getCallback()
  638.  
  639.     /**
  640.      * Get the callback function/method from an error object.
  641.      *
  642.      * @return mixed callback function or object/method array
  643.      * @access public
  644.      */
  645.     function getCallback() {
  646.         return $this->callback;
  647.     }
  648.  
  649.     // }}}
  650.     // {{{ getMessage()
  651.  
  652.  
  653.     /**
  654.      * Get the error message from an error object.
  655.      *
  656.      * @return  string  full error message
  657.      * @access public
  658.      */
  659.     function getMessage ()
  660.     {
  661.         return ($this->error_message_prefix . $this->message);
  662.     }
  663.  
  664.  
  665.     // }}}
  666.     // {{{ getCode()
  667.  
  668.     /**
  669.      * Get error code from an error object
  670.      *
  671.      * @return int error code
  672.      * @access public
  673.      */
  674.      function getCode()
  675.      {
  676.         return $this->code;
  677.      }
  678.  
  679.     // }}}
  680.     // {{{ getType()
  681.  
  682.     /**
  683.      * Get the name of this error/exception.
  684.      *
  685.      * @return string error/exception name (type)
  686.      * @access public
  687.      */
  688.     function getType ()
  689.     {
  690.         return get_class($this);
  691.     }
  692.  
  693.     // }}}
  694.     // {{{ getUserInfo()
  695.  
  696.     /**
  697.      * Get additional user-supplied information.
  698.      *
  699.      * @return string user-supplied information
  700.      * @access public
  701.      */
  702.     function getUserInfo ()
  703.     {
  704.         return $this->userinfo;
  705.     }
  706.  
  707.     // }}}
  708.     // {{{ getDebugInfo()
  709.  
  710.     /**
  711.      * Get additional debug information supplied by the application.
  712.      *
  713.      * @return string debug information
  714.      * @access public
  715.      */
  716.     function getDebugInfo ()
  717.     {
  718.         return $this->getUserInfo();
  719.     }
  720.  
  721.     // }}}
  722.     // {{{ addUserInfo()
  723.  
  724.     function addUserInfo($info)
  725.     {
  726.         if (empty($this->userinfo)) {
  727.             $this->userinfo = $info;
  728.         } else {
  729.             $this->userinfo .= " ** $info";
  730.         }
  731.     }
  732.  
  733.     // }}}
  734.     // {{{ toString()
  735.  
  736.     /**
  737.      * Make a string representation of this object.
  738.      *
  739.      * @return string a string with an object summary
  740.      * @access public
  741.      */
  742.     function toString() {
  743.         $modes = array();
  744.         $levels = array(E_USER_NOTICE  => 'notice',
  745.                         E_USER_WARNING => 'warning',
  746.                         E_USER_ERROR   => 'error');
  747.         if ($this->mode & PEAR_ERROR_CALLBACK) {
  748.             if (is_array($this->callback)) {
  749.                 $callback = get_class($this->callback[0]) . '::' .
  750.                     $this->callback[1];
  751.             } else {
  752.                 $callback = $this->callback;
  753.             }
  754.             return sprintf('[%s: message="%s" code=%d mode=callback '.
  755.                            'callback=%s prefix="%s" info="%s"]',
  756.                            get_class($this), $this->message, $this->code,
  757.                            $callback, $this->error_message_prefix,
  758.                            $this->userinfo);
  759.         }
  760.         if ($this->mode & PEAR_ERROR_CALLBACK) {
  761.             $modes[] = 'callback';
  762.         }
  763.         if ($this->mode & PEAR_ERROR_PRINT) {
  764.             $modes[] = 'print';
  765.         }
  766.         if ($this->mode & PEAR_ERROR_TRIGGER) {
  767.             $modes[] = 'trigger';
  768.         }
  769.         if ($this->mode & PEAR_ERROR_DIE) {
  770.             $modes[] = 'die';
  771.         }
  772.         if ($this->mode & PEAR_ERROR_RETURN) {
  773.             $modes[] = 'return';
  774.         }
  775.         return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
  776.                        'prefix="%s" info="%s"]',
  777.                        get_class($this), $this->message, $this->code,
  778.                        implode("|", $modes), $levels[$this->level],
  779.                        $this->error_message_prefix,
  780.                        $this->userinfo);
  781.     }
  782.  
  783.     // }}}
  784. }
  785.  
  786. register_shutdown_function("_PEAR_call_destructors");
  787.  
  788. /*
  789.  * Local Variables:
  790.  * mode: php
  791.  * tab-width: 4
  792.  * c-basic-offset: 4
  793.  * End:
  794.  */
  795. ?>
  796.