/zf/library/Zend/Gdata/Gapps/Error.php

http://github.com/eryx/php-framework-benchmark · PHP · 233 lines · 87 code · 18 blank · 128 comment · 4 complexity · 0b9bb054496af249d991144fa60c5810 MD5 · raw file

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