File: PhpdocError.php

package info (click to toggle)
php4 4.0.3pl1-0potato3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 15,168 kB
  • ctags: 20,556
  • sloc: ansic: 155,237; php: 10,827; sh: 9,608; yacc: 1,874; lex: 1,742; makefile: 788; java: 424; awk: 359; cpp: 335; perl: 181; xml: 57
file content (125 lines) | stat: -rw-r--r-- 2,772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* PHPDoc Error Handling class
*
* PHPDoc "throws" an error class derived from this class whenever
* an error occurs. PHPDoc saves the error object to the public array
* $this->err[] which exists in every PHPDoc class and tries to return 
* a useful value that indicates that something might have gone wrong.
*
* The class is widely equal to the PEAR error handling class PEAR_ERROR.
*
* @author		Ulf Wendel <ulf.wendel@phpdoc.de>
* @version 	1.0
* @package	PHPDoc
*/
class PhpdocError {
	
	/**
	* Name of the error object class used to construct the error message
	* @var		string	$classname
	*/
	var $classname 						= "PhpdocError";
	
	/**
	* Error message prefix.
	* @var		string	$error_message_prefix
	*/
	var $error_message_prefix	= "";

	/**
	* Error prepend, used for HTML formatting.
	* @var	string	$error_prepend
	*/	
	var $error_prepend = "<b>";
	
	/**
	* Error append, used for HTML formatting.
	* @var	string	$error_append
	*/
	var $error_append = "</b>";
	
	/**
	* The error message itself.
	*
	*	Use getMessage() to access it.
	*
	* @var	string	$message
	* @see	PhpdocError
	*/
	var $message = "";
	
	/**
	* File where the error occured.
	* @var	string	$file
	* @see	PhpdocError()
	*/
	var $file = "";
	
	/**
	* Line number where the error occured.
	* @var	int	$line
	* @see	PhpdocError()
	*/
	var $line = 0;
	
	/**
	* Array that describes how an error gets handled. 
	* @var	array	$errorHandling
	* @see	PhpdocError()
	*/
	var $errorHandling = array(
															"print"		=> false, 
															"trigger"	=> false,
															"die"			=> false
														);
	
	/**
	* Sets the error message, filename and linenumber.
	* @param	string	Errormessage
	* @param	string	Name of the file where the error occured, use __FILE__ for this
	* @param	string 	Linenumber where the error occured, use __LINE__ for this
	*/
	function PhpdocError($message, $file, $line) {
	
		$this->message = $message;
		$this->file = $file;
		$this->line = $line;

		if ($this->errorHandling["print"])
			$this->printMessage();
		
		if ($this->errorHandling["trigger"])
			trigger_error($this->getMessage(), "E_USER_NOTICE");
			
		if ($this->errorHandling["die"])
			die($this->getMessage);
		
	} // end func PhpdocError

	/**
	* Returns a string with the error message.
	* @access	public
	*/	
	function getMessage() {
	
		return sprintf("%s%s: %s [File: %s, Line: %s]%s",
										$this->error_prepend,
										$this->error_message_prefix,
										$this->message,
										$this->file,
										$this->line, 
										$this->error_append);
										
	} // end func getMessage
	
	/**
	* Prints the error message.
	* @brother	getMessage()
	*/
	function printMessage() {
		print $this->getMessage();
	} // end func printMessage
	
} // end class PhpdocError
?>