| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
class Error { |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
var $arrErrorList = array(); |
|---|
| 21 |
|
|---|
| 22 |
var $errors = 0; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
* |
|---|
| 26 |
* addError() |
|---|
| 27 |
* |
|---|
| 28 |
* @param strCommand string Command, which cause the Error |
|---|
| 29 |
* @param strMessage string additional Message, to describe the Error |
|---|
| 30 |
* @param intLine integer on which line the Error occours |
|---|
| 31 |
* @param strFile string in which File the Error occours |
|---|
| 32 |
* |
|---|
| 33 |
* @return - |
|---|
| 34 |
* |
|---|
| 35 |
**/ |
|---|
| 36 |
function addError( $strCommand, $strMessage, $intLine, $strFile ) { |
|---|
| 37 |
$this->arrErrorList[$this->errors]['command'] = $strCommand; |
|---|
| 38 |
$this->arrErrorList[$this->errors]['message'] = $strMessage; |
|---|
| 39 |
$this->arrErrorList[$this->errors]['line'] = $intLine; |
|---|
| 40 |
$this->arrErrorList[$this->errors]['file'] = basename( $strFile ); |
|---|
| 41 |
$this->errors++; |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
* |
|---|
| 46 |
* ErrorsAsHTML() |
|---|
| 47 |
* |
|---|
| 48 |
* @param - |
|---|
| 49 |
* |
|---|
| 50 |
* @return string string which contains a HTML table which can be used to echo out the errors |
|---|
| 51 |
* |
|---|
| 52 |
**/ |
|---|
| 53 |
function ErrorsAsHTML() { |
|---|
| 54 |
$strHTMLString = ""; |
|---|
| 55 |
$strWARNString = ""; |
|---|
| 56 |
$strHTMLhead = "<table width=\"100%\" border=\"0\">\n" |
|---|
| 57 |
. " <tr>\n" |
|---|
| 58 |
. " <td><font size=\"-1\"><b>File</b></font></td>\n" |
|---|
| 59 |
. " <td><font size=\"-1\"><b>Line</b></font></td>\n" |
|---|
| 60 |
. " <td><font size=\"-1\"><b>Command</b></font></td>\n" |
|---|
| 61 |
. " <td><font size=\"-1\"><b>Message</b></font></td>\n" |
|---|
| 62 |
. " </tr>\n"; |
|---|
| 63 |
$strHTMLfoot = "</table>"; |
|---|
| 64 |
|
|---|
| 65 |
if( $this->errors > 0 ) { |
|---|
| 66 |
foreach( $this->arrErrorList as $arrLine ) { |
|---|
| 67 |
if( $arrLine['command'] == "WARN" ) { |
|---|
| 68 |
$strWARNString .= "<font size=\"-1\"><b>WARNING: " . htmlspecialchars( $arrLine['message'] ) . "</b></font><br/>\n"; |
|---|
| 69 |
} else { |
|---|
| 70 |
$strHTMLString .= " <tr>\n" |
|---|
| 71 |
. " <td><font size=\"-1\">" . htmlspecialchars( $arrLine['file'] ) . "</font></td>\n" |
|---|
| 72 |
. " <td><font size=\"-1\">" . $arrLine['line'] . "</font></td>\n" |
|---|
| 73 |
. " <td><font size=\"-1\">" . htmlspecialchars( $arrLine['command'] ) . "</font></td>\n" |
|---|
| 74 |
. " <td><font size=\"-1\">" . htmlspecialchars( $arrLine['message'] ) . "</font></td>\n" |
|---|
| 75 |
. " </tr>\n"; |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
if( !empty( $strHTMLString ) ) { |
|---|
| 81 |
$strHTMLString = $strWARNString . $strHTMLhead . $strHTMLString . $strHTMLfoot; |
|---|
| 82 |
} else { |
|---|
| 83 |
$strHTMLString = $strWARNString; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
return $strHTMLString; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
* |
|---|
| 91 |
* ErrorsAsText() |
|---|
| 92 |
* |
|---|
| 93 |
* @param - |
|---|
| 94 |
* |
|---|
| 95 |
* @return string string which contains a table which can be used to echo out the errors |
|---|
| 96 |
* |
|---|
| 97 |
**/ |
|---|
| 98 |
function ErrorsAsText() { |
|---|
| 99 |
$strHTMLString = ""; |
|---|
| 100 |
$strWARNString = ""; |
|---|
| 101 |
$strHTMLhead = sprintf("%24s %6s %40s %s\n","File", "Line", "Command", "Message"); |
|---|
| 102 |
$strHTMLfoot = "\n"; |
|---|
| 103 |
|
|---|
| 104 |
if( $this->errors > 0 ) { |
|---|
| 105 |
foreach( $this->arrErrorList as $arrLine ) { |
|---|
| 106 |
if( $arrLine['command'] == "WARN" ) { |
|---|
| 107 |
$strWARNString .= "WARNING: " . $arrLine['message'] . "\n"; |
|---|
| 108 |
} else { |
|---|
| 109 |
$strHTMLString .= sprintf("%24s %6s %40s %s\n",$arrLine['file'], $arrLine['line'], $arrLine['command'], $arrLine['message'] ); |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
if( !empty( $strHTMLString ) ) { |
|---|
| 115 |
$strHTMLString = $strWARNString . $strHTMLhead . $strHTMLString . $strHTMLfoot; |
|---|
| 116 |
} else { |
|---|
| 117 |
$strHTMLString = $strWARNString; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
return $strHTMLString; |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
* |
|---|
| 125 |
* ErrorsExist() |
|---|
| 126 |
* |
|---|
| 127 |
* @param - |
|---|
| 128 |
* |
|---|
| 129 |
* @return true there are errors logged |
|---|
| 130 |
* false no errors logged |
|---|
| 131 |
* |
|---|
| 132 |
**/ |
|---|
| 133 |
function ErrorsExist() { |
|---|
| 134 |
if( $this->errors > 0 ) { |
|---|
| 135 |
return true; |
|---|
| 136 |
} else { |
|---|
| 137 |
return false; |
|---|
| 138 |
} |
|---|
| 139 |
} |
|---|
| 140 |
} |
|---|
| 141 |
?> |
|---|
| 142 |
|
|---|