3 * A very base error class.
5 * Provides a basic uniform API for setting and testing error conditions and
9 * @author Tim Perdue <tperdue@valnux.com>
12 * This file is part of GForge.
14 * GForge is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * GForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GForge; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 define('ERROR__NO_ERROR', 0);
30 define('ERROR__UNCLASSIFIED_ERROR', 1);
31 define('ERROR__PERMISSION_DENIED_ERROR', 2);
32 define('ERROR__INVALID_EMAIL_ERROR', 3);
33 define('ERROR__ON_UPDATE_ERROR', 4);
34 define('ERROR__GROUPID_ERROR', 5);
35 define('ERROR__MISSING_PARAMS_ERROR', 6);
39 * The current error state.
41 * @var bool $error_state.
46 * The current error message(s).
48 * @var string $error_message.
53 * The current error code
55 * @var int $error_code.
60 * Error() - Constructor.
61 * Constructor for the Error class.
62 * Sets the error state to false.
67 $this->error_state=false;
68 $this->error_code=ERROR__NO_ERROR;
72 * setError() - Sets the error string.
73 * Set the error string $error_message to the value of $string
74 * and enable the $error_state flag.
76 * @param string The error string to set.
77 * @param int The error code
79 function setError($string, $code=ERROR__UNCLASSIFIED_ERROR) {
80 $this->error_state=true;
81 $this->error_message=$string;
82 $this->error_code=$code;
86 * clearError() - Clear the current error.
87 * Clear the current error string and disable the $error_state flag.
90 function clearError() {
91 $this->error_state=false;
92 $this->error_code=ERROR__NO_ERROR;
93 $this->error_message='';
97 * getErrorMessage() - Retrieve the error message string.
98 * Returns the value of $error_message.
100 * @return $error_message The current error message string.
103 function getErrorMessage() {
104 if ($this->error_state) {
105 return $this->error_message;
112 * isError() - Determines the current error state.
113 * This function returns the current value of $error_state.
115 * @return $error_state The boolean error status.
119 return $this->error_state;
124 * setPermissionDeniedError() - sets a Permission Denied error
125 * retrieves the localized error string for Permission Denied and calls exit_error()
129 function setPermissionDeniedError(){
130 $this->setError(_('Permission denied.'), ERROR__PERMISSION_DENIED_ERROR);
134 * isPermissionDeniedError() - Determines if it is a permission denied error
138 function isPermissionDeniedError(){
139 return ($this->error_code == ERROR__PERMISSION_DENIED_ERROR);
143 * setInvalidEmailError() - sets a Invalid Email error
144 * retrieves the localized error string for Invalid Email and calls exit_error()
146 function setInvalidEmailError(){
147 $this->setError(_('Invalid Email Address'), ERROR__INVALID_EMAIL_ERROR);
151 * isInvalidEmailError() - Determines if it is an invalid email error
155 function isInvalidEmailError(){
156 return ($this->error_code == ERROR__INVALID_EMAIL_ERROR);
160 * setOnUpdateError() - sets an On Update Error
161 * retrieves the localized error string for On Update
163 * @param string The db result to be written.
166 function setOnUpdateError($result=""){
167 $this->setError(sprintf(_('Error On Update:'), $result), ERROR__ON_UPDATE_ERROR);
171 * isOnUpdateError() - Determines if it is an on update error
175 function isOnUpdateError(){
176 return ($this->error_code == ERROR__ON_UPDATE_ERROR);
180 * setGroupIdError() - sets an Group ID Error
181 * retrieves the localized error string for Group ID
183 function setGroupIdError(){
184 $this->setError(_('Group_id in db result does not match Group Object'), ERROR__GROUPID_ERROR);
189 * isGroupIdError() - Determines if it is a group ID error
193 function isGroupIdError(){
194 return ($this->error_code == ERROR__GROUPID_ERROR);
198 * setMissingParamsError() - sets an Group ID Error
199 * retrieves the localized error string for missing pparams
201 function setMissingParamsError(){
202 $this->setError(_('Missing Parameters'), ERROR__MISSING_PARAMS_ERROR);
206 * isMissingParamsError() - Determines if it is a missing params error
210 function isMissingParamsError(){
211 return ($this->error_code == ERROR__MISSING_PARAMS_ERROR);
218 // c-file-style: "bsd"