PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/gforge/common/include/Error.class.php

https://github.com/neymanna/fusionforge
PHP | 217 lines | 68 code | 24 blank | 125 comment | 7 complexity | 4b3e68291f42c365b0c4b88587dec37d MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * FusionForge base error class
  4. *
  5. * Copyright 1999-2001, VA Linux Systems, Inc.
  6. *
  7. * This file is part of FusionForge.
  8. *
  9. * FusionForge is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published
  11. * by the Free Software Foundation; either version 2 of the License,
  12. * or (at your option) any later version.
  13. *
  14. * FusionForge is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with FusionForge; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  22. * USA
  23. */
  24. define('ERROR__NO_ERROR', 0);
  25. define('ERROR__UNCLASSIFIED_ERROR', 1);
  26. define('ERROR__PERMISSION_DENIED_ERROR', 2);
  27. define('ERROR__INVALID_EMAIL_ERROR', 3);
  28. define('ERROR__ON_UPDATE_ERROR', 4);
  29. define('ERROR__GROUPID_ERROR', 5);
  30. define('ERROR__MISSING_PARAMS_ERROR', 6);
  31. class Error {
  32. /**
  33. * The current error state.
  34. *
  35. * @var bool $error_state.
  36. */
  37. var $error_state;
  38. /**
  39. * The current error message(s).
  40. *
  41. * @var string $error_message.
  42. */
  43. var $error_message;
  44. /**
  45. * The current error code
  46. *
  47. * @var int $error_code.
  48. */
  49. var $error_code;
  50. /**
  51. * Error() - Constructor.
  52. * Constructor for the Error class.
  53. * Sets the error state to false.
  54. *
  55. */
  56. function Error() {
  57. //nothing
  58. $this->error_state=false;
  59. $this->error_code=ERROR__NO_ERROR;
  60. }
  61. /**
  62. * setError() - Sets the error string.
  63. * Set the error string $error_message to the value of $string
  64. * and enable the $error_state flag.
  65. *
  66. * @param string The error string to set.
  67. * @param int The error code
  68. */
  69. function setError($string, $code=ERROR__UNCLASSIFIED_ERROR) {
  70. $this->error_state=true;
  71. $this->error_message=$string;
  72. $this->error_code=$code;
  73. }
  74. /**
  75. * clearError() - Clear the current error.
  76. * Clear the current error string and disable the $error_state flag.
  77. *
  78. */
  79. function clearError() {
  80. $this->error_state=false;
  81. $this->error_code=ERROR__NO_ERROR;
  82. $this->error_message='';
  83. }
  84. /**
  85. * getErrorMessage() - Retrieve the error message string.
  86. * Returns the value of $error_message.
  87. *
  88. * @return $error_message The current error message string.
  89. *
  90. */
  91. function getErrorMessage() {
  92. if ($this->error_state) {
  93. return $this->error_message;
  94. } else {
  95. return 'No Error';
  96. }
  97. }
  98. /**
  99. * isError() - Determines the current error state.
  100. * This function returns the current value of $error_state.
  101. *
  102. * @return $error_state The boolean error status.
  103. *
  104. */
  105. function isError() {
  106. return $this->error_state;
  107. }
  108. /**
  109. * setPermissionDeniedError() - sets a Permission Denied error
  110. * retrieves the localized error string for Permission Denied and calls exit_error()
  111. *
  112. *
  113. */
  114. function setPermissionDeniedError(){
  115. $this->setError(_('Permission denied.'), ERROR__PERMISSION_DENIED_ERROR);
  116. }
  117. /**
  118. * isPermissionDeniedError() - Determines if it is a permission denied error
  119. *
  120. * @return boolean
  121. */
  122. function isPermissionDeniedError(){
  123. return ($this->error_code == ERROR__PERMISSION_DENIED_ERROR);
  124. }
  125. /**
  126. * setInvalidEmailError() - sets a Invalid Email error
  127. * retrieves the localized error string for Invalid Email and calls exit_error()
  128. */
  129. function setInvalidEmailError(){
  130. $this->setError(_('Invalid Email Address'), ERROR__INVALID_EMAIL_ERROR);
  131. }
  132. /**
  133. * isInvalidEmailError() - Determines if it is an invalid email error
  134. *
  135. * @return boolean
  136. */
  137. function isInvalidEmailError(){
  138. return ($this->error_code == ERROR__INVALID_EMAIL_ERROR);
  139. }
  140. /**
  141. * setOnUpdateError() - sets an On Update Error
  142. * retrieves the localized error string for On Update
  143. *
  144. * @param string The db result to be written.
  145. *
  146. */
  147. function setOnUpdateError($result=""){
  148. $this->setError(sprintf(_('Error On Update:'), $result), ERROR__ON_UPDATE_ERROR);
  149. }
  150. /**
  151. * isOnUpdateError() - Determines if it is an on update error
  152. *
  153. * @return boolean
  154. */
  155. function isOnUpdateError(){
  156. return ($this->error_code == ERROR__ON_UPDATE_ERROR);
  157. }
  158. /**
  159. * setGroupIdError() - sets an Group ID Error
  160. * retrieves the localized error string for Group ID
  161. */
  162. function setGroupIdError(){
  163. $this->setError(_('Group_id in db result does not match Group Object'), ERROR__GROUPID_ERROR);
  164. }
  165. /**
  166. * isGroupIdError() - Determines if it is a group ID error
  167. *
  168. * @return boolean
  169. */
  170. function isGroupIdError(){
  171. return ($this->error_code == ERROR__GROUPID_ERROR);
  172. }
  173. /**
  174. * setMissingParamsError() - sets an Group ID Error
  175. * retrieves the localized error string for missing pparams
  176. */
  177. function setMissingParamsError(){
  178. $this->setError(_('Missing Parameters'), ERROR__MISSING_PARAMS_ERROR);
  179. }
  180. /**
  181. * isMissingParamsError() - Determines if it is a missing params error
  182. *
  183. * @return boolean
  184. */
  185. function isMissingParamsError(){
  186. return ($this->error_code == ERROR__MISSING_PARAMS_ERROR);
  187. }
  188. }
  189. // Local Variables:
  190. // mode: php
  191. // c-file-style: "bsd"
  192. // End:
  193. ?>