home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / exceptions / PhpdocError.php
Encoding:
PHP Script  |  2001-02-18  |  3.5 KB  |  134 lines

  1. <?php
  2. /**
  3. * PHPDoc Error Handling class
  4. *
  5. * TODO: make this 100% PEAR compatible
  6. *
  7. * PHPDoc "throws" an error class derived from this class whenever
  8. * an error occurs. PHPDoc saves the error object to the public array
  9. * $this->err[] which exists in every PHPDoc class and tries to return 
  10. * a useful value that indicates that something might have gone wrong.
  11. *
  12. * The class is widely equal to the PEAR error handling class PEAR_ERROR.
  13. *
  14. * @author   Ulf Wendel <ulf.wendel@phpdoc.de>
  15. * @version  $Id: PhpdocError.php,v 1.3 2001/02/18 15:36:32 uw Exp $
  16. * @package  PHPDoc
  17. */
  18. class PhpdocError {
  19.     
  20.     /**
  21.     * Name of the error object class used to construct the error message
  22.     *
  23.     * @var  string  $classname
  24.     */
  25.     var $classname  = "PhpdocError";
  26.     
  27.     /**
  28.     * Error message prefix.
  29.     *
  30.     * @var  string  $error_message_prefix
  31.     */
  32.     var $error_message_prefix   = "";
  33.  
  34.     /**
  35.     * Error prepend, used for HTML formatting.
  36.     *
  37.     * @var  string  $error_prepend
  38.     */    
  39.     var $error_prepend = "<b>";
  40.     
  41.     /**
  42.     * Error append, used for HTML formatting.
  43.     *
  44.     * @var  string  $error_append
  45.     */
  46.     var $error_append = "</b>";
  47.     
  48.     /**
  49.     * The error message itself.
  50.     *
  51.     * Use getMessage() to access it.
  52.     *
  53.     * @var  string  $message
  54.     * @see  PhpdocError()
  55.     */
  56.     var $message = "";
  57.     
  58.     /**
  59.     * File where the error occured.
  60.     *
  61.     * @var  string  $file
  62.     * @see  PhpdocError()
  63.     */
  64.     var $file = "";
  65.     
  66.     /**
  67.     * Line number where the error occured.
  68.     *
  69.     * @var  integer $line
  70.     * @see  PhpdocError()
  71.     */
  72.     var $line = 0;
  73.     
  74.     /**
  75.     * Array that describes how an error gets handled. 
  76.     * @var    array    $errorHandling
  77.     * @see    PhpdocError()
  78.     */
  79.     var $errorHandling = array(
  80.                                 "print"     => false, 
  81.                                 "trigger"   => false,
  82.                                 "die"       => false
  83.                             );
  84.     
  85.     /**
  86.     * Sets the error message, filename and linenumber.
  87.     *
  88.     * @param    string  Errormessage
  89.     * @param    string  Name of the file where the error occured, use __FILE__ for this
  90.     * @param    string  Linenumber where the error occured, use __LINE__ for this
  91.     */
  92.     function PhpdocError($message, $file, $line) {
  93.     
  94.         $this->message = $message;
  95.         $this->file = $file;
  96.         $this->line = $line;
  97.  
  98.         if ($this->errorHandling["print"])
  99.             $this->printMessage();
  100.         
  101.         if ($this->errorHandling["trigger"])
  102.             trigger_error($this->getMessage(), "E_USER_NOTICE");
  103.             
  104.         if ($this->errorHandling["die"])
  105.             die($this->getMessage);
  106.         
  107.     } // end func PhpdocError
  108.  
  109.     /**
  110.     * Returns a string with the error message.
  111.     * @access    public
  112.     */    
  113.     function getMessage() {
  114.     
  115.         return sprintf("%s%s: %s [File: %s, Line: %s]%s",
  116.                         $this->error_prepend,
  117.                         $this->error_message_prefix,
  118.                         $this->message,
  119.                         $this->file,
  120.                         $this->line, 
  121.                         $this->error_append);
  122.                                         
  123.     } // end func getMessage
  124.     
  125.     /**
  126.     * Prints the error message.
  127.     * @brother    getMessage()
  128.     */
  129.     function printMessage() {
  130.         print $this->getMessage();
  131.     } // end func printMessage
  132.     
  133. } // end class PhpdocError
  134. ?>