Changeset 3730:5c45a5df9a59 for inc/core/class.dc.error.php
- Timestamp:
- 03/08/18 17:58:39 (8 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.error.php
r3615 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 /** 15 * @ingroup DC_CORE16 * @brief Error class17 *18 * dcError is a very simple error class, with a stack. Call dcError::add to19 * add an error in stack. In administration area, errors are automatically20 * displayed.21 */15 * @ingroup DC_CORE 16 * @brief Error class 17 * 18 * dcError is a very simple error class, with a stack. Call dcError::add to 19 * add an error in stack. In administration area, errors are automatically 20 * displayed. 21 */ 22 22 class dcError 23 23 { 24 25 26 27 28 29 30 31 32 33 24 /** @var array Errors stack */ 25 protected $errors = array(); 26 /** @var boolean True if stack is not empty */ 27 protected $flag = false; 28 /** @var string HTML errors list pattern */ 29 protected $html_list = "<ul>\n%s</ul>\n"; 30 /** @var string HTML error item pattern */ 31 protected $html_item = "<li>%s</li>\n"; 32 /** @var string HTML error single pattern */ 33 protected $html_single = "<p>%s</p>\n"; 34 34 35 36 37 38 39 40 41 42 35 /** 36 * Object string representation. Returns errors stack. 37 * 38 * @return string 39 */ 40 public function __toString() 41 { 42 $res = ''; 43 43 44 foreach ($this->errors as $msg) 45 { 46 $res .= $msg."\n"; 47 } 44 foreach ($this->errors as $msg) { 45 $res .= $msg . "\n"; 46 } 48 47 49 50 48 return $res; 49 } 51 50 52 53 54 55 * @param string $msgError message56 57 58 59 $this->flag= true;60 61 51 /** 52 * Adds an error to stack. 53 * 54 * @param string $msg Error message 55 */ 56 public function add($msg) 57 { 58 $this->flag = true; 59 $this->errors[] = $msg; 60 } 62 61 63 64 65 66 67 68 69 70 71 62 /** 63 * Returns the value of <var>flag</var> property. True if errors stack is not empty 64 * 65 * @return boolean 66 */ 67 public function flag() 68 { 69 return $this->flag; 70 } 72 71 73 74 75 76 77 78 $this->flag= false;79 80 72 /** 73 * Resets errors stack. 74 */ 75 public function reset() 76 { 77 $this->flag = false; 78 $this->errors = array(); 79 } 81 80 82 83 84 85 86 87 88 89 90 81 /** 82 * Returns <var>errors</var> property. 83 * 84 * @return array 85 */ 86 public function getErrors() 87 { 88 return $this->errors; 89 } 91 90 92 93 94 95 * @param string $listHTML errors list pattern96 * @param string $itemHTML error item pattern97 98 public function setHTMLFormat($list,$item,$single=null)99 100 101 102 103 104 105 91 /** 92 * Sets <var>list</var> and <var>item</var> properties. 93 * 94 * @param string $list HTML errors list pattern 95 * @param string $item HTML error item pattern 96 */ 97 public function setHTMLFormat($list, $item, $single = null) 98 { 99 $this->html_list = $list; 100 $this->html_item = $item; 101 if ($single) { 102 $this->html_single = $single; 103 } 104 } 106 105 107 108 109 110 111 112 113 114 106 /** 107 * Returns errors stack as HTML. 108 * 109 * @return string 110 */ 111 public function toHTML() 112 { 113 $res = ''; 115 114 116 if ($this->flag) 117 { 118 if (count($this->errors == 1)) { 119 $res = sprintf($this->html_single,$this->errors[0]); 120 } else { 121 foreach ($this->errors as $msg) { 122 $res .= sprintf($this->html_item,$msg); 123 } 124 $res = sprintf($this->html_list,$res); 125 } 126 } 115 if ($this->flag) { 116 if (count($this->errors == 1)) { 117 $res = sprintf($this->html_single, $this->errors[0]); 118 } else { 119 foreach ($this->errors as $msg) { 120 $res .= sprintf($this->html_item, $msg); 121 } 122 $res = sprintf($this->html_list, $res); 123 } 124 } 127 125 128 129 126 return $res; 127 } 130 128 }
Note: See TracChangeset
for help on using the changeset viewer.