[ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2005 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 /** 24 @ingroup DC_CORE 25 @brief Error class 26 27 dcError is a very simple error class, with a stack. Call dcError::add to 28 add an error in stack. In administration area, errors are automatically 29 displayed. 30 */ 31 class dcError 32 { 33 protected $errors = array(); ///< <b>array</b> Errors stack 34 protected $flag = false; ///< <b>boolean</b> True if stack is not empty 35 protected $html_list = "<ul>\n%s</ul>\n"; ///< <b>string</b> HTML errors list pattern 36 protected $html_item = "<li>%s</li>\n"; ///< <b>string</b> HTML error item pattern 37 38 /** 39 Object constructor. 40 */ 41 public function __construct() 42 { 43 $this->code = 0; 44 $this->msg = ''; 45 } 46 47 /** 48 Object string representation. Returns errors stack. 49 50 @return <b>string</b> 51 */ 52 public function __toString() 53 { 54 $res = ''; 55 56 foreach ($this->errors as $msg) 57 { 58 $res .= $msg."\n"; 59 } 60 61 return $res; 62 } 63 64 /** 65 Adds an error to stack. 66 67 @param msg <b>string</b> Error message 68 */ 69 public function add($msg) 70 { 71 $this->flag = true; 72 $this->errors[] = $msg; 73 } 74 75 /** 76 Returns the value of <var>flag</var> property. 77 78 @return <b>boolean</b> True if errors stack is not empty 79 */ 80 public function flag() 81 { 82 return $this->flag; 83 } 84 85 /** 86 Resets errors stack. 87 */ 88 public function reset() 89 { 90 $this->flag = false; 91 $this->errors = array(); 92 } 93 94 /** 95 Returns <var>errors</var> property. 96 97 @return <b>array</b> 98 */ 99 public function getErrors() 100 { 101 return $this->errors; 102 } 103 104 /** 105 Sets <var>list</var> and <var>item</var> properties. 106 107 @param list <b>string</b> HTML errors list pattern 108 @param item <b>string</b> HTML error item pattern 109 */ 110 public function setHTMLFormat($list,$item) 111 { 112 $this->html_list = $list; 113 $this->html_item = $item; 114 } 115 116 /** 117 Returns errors stack as HTML. 118 119 @return <b>string</b> 120 */ 121 public function toHTML() 122 { 123 $res = ''; 124 125 if ($this->flag) 126 { 127 foreach ($this->errors as $msg) 128 { 129 $res .= sprintf($this->html_item,$msg); 130 } 131 132 $res = sprintf($this->html_list,$res); 133 } 134 135 return $res; 136 } 137 } 138 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |