Error.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Gapps
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Zend_Gdata_App_Base
  23. */
  24. require_once 'Zend/Gdata/App/Base.php';
  25. /**
  26. * Gdata Gapps Error class. This class is used to represent errors returned
  27. * within an AppsForYourDomainErrors message received from the Google Apps
  28. * servers.
  29. *
  30. * Several different errors may be represented by this class, determined by
  31. * the error code returned by the server. For a list of error codes
  32. * available at the time of this writing, see getErrorCode.
  33. *
  34. * @category Zend
  35. * @package Zend_Gdata
  36. * @subpackage Gapps
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Gdata_Gapps_Error extends Zend_Gdata_App_Base
  41. {
  42. // Error codes as defined at
  43. // http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d
  44. const UNKNOWN_ERROR = 1000;
  45. const USER_DELETED_RECENTLY = 1100;
  46. const USER_SUSPENDED = 1101;
  47. const DOMAIN_USER_LIMIT_EXCEEDED = 1200;
  48. const DOMAIN_ALIAS_LIMIT_EXCEEDED = 1201;
  49. const DOMAIN_SUSPENDED = 1202;
  50. const DOMAIN_FEATURE_UNAVAILABLE = 1203;
  51. const ENTITY_EXISTS = 1300;
  52. const ENTITY_DOES_NOT_EXIST = 1301;
  53. const ENTITY_NAME_IS_RESERVED = 1302;
  54. const ENTITY_NAME_NOT_VALID = 1303;
  55. const INVALID_GIVEN_NAME = 1400;
  56. const INVALID_FAMILY_NAME = 1401;
  57. const INVALID_PASSWORD = 1402;
  58. const INVALID_USERNAME = 1403;
  59. const INVALID_HASH_FUNCTION_NAME = 1404;
  60. const INVALID_HASH_DIGEST_LENGTH = 1405;
  61. const INVALID_EMAIL_ADDRESS = 1406;
  62. const INVALID_QUERY_PARAMETER_VALUE = 1407;
  63. const TOO_MANY_RECIPIENTS_ON_EMAIL_LIST = 1500;
  64. protected $_errorCode = null;
  65. protected $_reason = null;
  66. protected $_invalidInput = null;
  67. public function __construct($errorCode = null, $reason = null,
  68. $invalidInput = null) {
  69. parent::__construct("Google Apps error received: $errorCode ($reason)");
  70. $this->_errorCode = $errorCode;
  71. $this->_reason = $reason;
  72. $this->_invalidInput = $invalidInput;
  73. }
  74. /**
  75. * Set the error code for this exception. For more information about
  76. * error codes, see getErrorCode.
  77. *
  78. * @see getErrorCode
  79. * @param integer $value The new value for the error code.
  80. */
  81. public function setErrorCode($value) {
  82. $this->_errorCode = $value;
  83. }
  84. /**
  85. * Get the error code for this exception. Currently valid values are
  86. * available as constants within this class. These values are:
  87. *
  88. * UNKNOWN_ERROR (1000)
  89. * USER_DELETED_RECENTLY (1100)
  90. * USER_SUSPENDED (1101)
  91. * DOMAIN_USER_LIMIT_EXCEEDED (1200)
  92. * DOMAIN_ALIAS_LIMIT_EXCEEDED (1201)
  93. * DOMAIN_SUSPENDED (1202)
  94. * DOMAIN_FEATURE_UNAVAILABLE (1203)
  95. * ENTITY_EXISTS (1300)
  96. * ENTITY_DOES_NOT_EXIST (1301)
  97. * ENTITY_NAME_IS_RESERVED (1302)
  98. * ENTITY_NAME_NOT_VALID (1303)
  99. * INVALID_GIVEN_NAME (1400)
  100. * INVALID_FAMILY_NAME (1401)
  101. * INVALID_PASSWORD (1402)
  102. * INVALID_USERNAME (1403)
  103. * INVALID_HASH_FUNCTION_NAME (1404)
  104. * INVALID_HASH_DIGEST_LENGTH (1405)
  105. * INVALID_EMAIL_ADDRESS (1406)
  106. * INVALID_QUERY_PARAMETER_VALUE (1407)
  107. * TOO_MANY_RECIPIENTS_ON_EMAIL_LIST (1500)
  108. *
  109. * Numbers in parenthesis indicate the actual integer value of the
  110. * constant. This list should not be treated as exhaustive, as additional
  111. * error codes may be added at any time.
  112. *
  113. * For more information about these codes and their meaning, please
  114. * see Appendix D of the Google Apps Provisioning API Reference.
  115. *
  116. * @link http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d Google Apps Provisioning API Reference: Appendix D - Gdata Error Codes
  117. * @see setErrorCode
  118. * @return integer The error code returned by the Google Apps server.
  119. */
  120. public function getErrorCode() {
  121. return $this->_errorCode;
  122. }
  123. /**
  124. * Set human-readable text describing the reason this exception occurred.
  125. *
  126. * @see getReason
  127. * @param string $value The reason this exception occurred.
  128. */
  129. public function setReason($value) {
  130. $this->_reason = $value;
  131. }
  132. /**
  133. * Get human-readable text describing the reason this exception occurred.
  134. *
  135. * @see setReason
  136. * @return string The reason this exception occurred.
  137. */
  138. public function getReason() {
  139. return $this->_reason;
  140. }
  141. /**
  142. * Set the invalid input which caused this exception.
  143. *
  144. * @see getInvalidInput
  145. * @param string $value The invalid input that triggered this exception.
  146. */
  147. public function setInvalidInput($value) {
  148. $this->_invalidInput = $value;
  149. }
  150. /**
  151. * Set the invalid input which caused this exception.
  152. *
  153. * @see setInvalidInput
  154. * @return string The reason this exception occurred.
  155. */
  156. public function getInvalidInput() {
  157. return $this->_invalidInput;
  158. }
  159. /**
  160. * Retrieves a DOMElement which corresponds to this element and all
  161. * child properties. This is used to build an entry back into a DOM
  162. * and eventually XML text for application storage/persistence.
  163. *
  164. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  165. * @return DOMElement The DOMElement representing this element and all
  166. * child properties.
  167. */
  168. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  169. {
  170. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  171. if ($this->_errorCode !== null) {
  172. $element->setAttribute('errorCode', $this->_errorCode);
  173. }
  174. if ($this->_reason !== null) {
  175. $element->setAttribute('reason', $this->_reason);
  176. }
  177. if ($this->_invalidInput !== null) {
  178. $element->setAttribute('invalidInput', $this->_invalidInput);
  179. }
  180. return $element;
  181. }
  182. /**
  183. * Given a DOMNode representing an attribute, tries to map the data into
  184. * instance members. If no mapping is defined, the name and value are
  185. * stored in an array.
  186. *
  187. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  188. */
  189. protected function takeAttributeFromDOM($attribute)
  190. {
  191. switch ($attribute->localName) {
  192. case 'errorCode':
  193. $this->_errorCode = $attribute->nodeValue;
  194. break;
  195. case 'reason':
  196. $this->_reason = $attribute->nodeValue;
  197. break;
  198. case 'invalidInput':
  199. $this->_invalidInput = $attribute->nodeValue;
  200. break;
  201. default:
  202. parent::takeAttributeFromDOM($attribute);
  203. }
  204. }
  205. /**
  206. * Get a human readable version of this exception.
  207. *
  208. * @return string
  209. */
  210. public function __toString() {
  211. return "Error " . $this->getErrorCode() . ": " . $this->getReason() .
  212. "\n\tInvalid Input: \"" . $this->getInvalidInput() . "\"";
  213. }
  214. }