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