Error.php
Go to the documentation of this file.
00001 <?php 00002 00005 00026 class Error 00027 { 00029 public $id = 0; 00030 00032 public $webservice = ""; 00033 00035 public $name = ""; 00036 00038 public $description = ""; 00039 00041 public $debugInfo = ""; 00042 00044 public $mime = ""; 00045 00047 public $level = ""; 00048 00067 function __construct($id, $webservice, $name, $description, $debugInfo, $mime, $level) 00068 { 00069 $this->id = $id; 00070 $this->webservice = $webservice; 00071 $this->name = $name; 00072 $this->description = $description; 00073 $this->debugInfo = $debugInfo; 00074 $this->mime = $mime; 00075 $this->level = $level; 00076 } 00077 00078 function __destruct() { } 00079 00088 public function getError() 00089 { 00090 $error = ""; 00091 00092 switch($this->mime) 00093 { 00094 case "application/json": 00095 $error = " { 00096 \"id\": \"" . $this->jsonEncode($this->id) . "\", 00097 \"webservice\": \"" . $this->jsonEncode($this->webservice) . "\", 00098 \"name\": \"" . $this->jsonEncode($this->name) . "\", 00099 \"description\": \"" . $this->jsonEncode($this->description) . "\", 00100 \"debugInformation\": \"" . $this->jsonEncode($this->debugInfo) . "\", 00101 \"level\": \"" . $this->jsonEncode($this->level) . "\" 00102 } 00103 "; 00104 break; 00105 00106 case "text/plain": 00107 $error = $this->id . ", " . $this->webservice . ", " . $this->name . ", " . $this->description . ", " 00108 . $this->debugInfo; 00109 break; 00110 00111 case "text/xml": 00112 default: 00113 $error = " <?xml version=\"1.0\" encoding=\"utf-8\"?> 00114 <error> 00115 <id>" . $this->xmlEncode($this->id) . "</id> 00116 <webservice>" . $this->xmlEncode($this->webservice) . "</webservice> 00117 <name>" . $this->xmlEncode($this->name) . "</name> 00118 <description>" . $this->xmlEncode($this->description) . "</description> 00119 <debugInformation>" . $this->xmlEncode($this->debugInfo) . "</debugInformation> 00120 <level>" . $this->xmlEncode($this->level) . "</level> 00121 </error> 00122 "; 00123 break; 00124 } 00125 00126 return ($error); 00127 } 00128 00141 public function xmlEncode($string) 00142 { return str_replace(array ("\\", "&", "<", ">"), array ("%5C", "&", "<", ">"), $string); } 00143 00156 public function jsonEncode($string) { return str_replace(array ('\\', '"'), array ('\\\\', '\\"'), $string); } 00157 } 00158 00160 00161 ?>
