8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
27 require_once 'Zend/Gdata/App/Base.php';
30 * Gdata Gapps Error class. This class is used to represent errors returned
31 * within an AppsForYourDomainErrors message received from the Google Apps
34 * Several different errors may be represented by this class, determined by
35 * the error code returned by the server. For a list of error codes
36 * available at the time of this writing, see getErrorCode.
41 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
42 * @license http://framework.zend.com/license/new-bsd New BSD License
44 class Zend_Gdata_Gapps_Error
extends Zend_Gdata_App_Base
47 // Error codes as defined at
48 // http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d
50 const UNKNOWN_ERROR
= 1000;
51 const USER_DELETED_RECENTLY
= 1100;
52 const USER_SUSPENDED
= 1101;
53 const DOMAIN_USER_LIMIT_EXCEEDED
= 1200;
54 const DOMAIN_ALIAS_LIMIT_EXCEEDED
= 1201;
55 const DOMAIN_SUSPENDED
= 1202;
56 const DOMAIN_FEATURE_UNAVAILABLE
= 1203;
57 const ENTITY_EXISTS
= 1300;
58 const ENTITY_DOES_NOT_EXIST
= 1301;
59 const ENTITY_NAME_IS_RESERVED
= 1302;
60 const ENTITY_NAME_NOT_VALID
= 1303;
61 const INVALID_GIVEN_NAME
= 1400;
62 const INVALID_FAMILY_NAME
= 1401;
63 const INVALID_PASSWORD
= 1402;
64 const INVALID_USERNAME
= 1403;
65 const INVALID_HASH_FUNCTION_NAME
= 1404;
66 const INVALID_HASH_DIGEST_LENGTH
= 1405;
67 const INVALID_EMAIL_ADDRESS
= 1406;
68 const INVALID_QUERY_PARAMETER_VALUE
= 1407;
69 const TOO_MANY_RECIPIENTS_ON_EMAIL_LIST
= 1500;
71 protected $_errorCode = null;
72 protected $_reason = null;
73 protected $_invalidInput = null;
75 public function __construct($errorCode = null, $reason = null,
76 $invalidInput = null) {
77 parent
::__construct("Google Apps error received: $errorCode ($reason)");
78 $this->_errorCode
= $errorCode;
79 $this->_reason
= $reason;
80 $this->_invalidInput
= $invalidInput;
84 * Set the error code for this exception. For more information about
85 * error codes, see getErrorCode.
88 * @param integer $value The new value for the error code.
90 public function setErrorCode($value) {
91 $this->_errorCode
= $value;
95 * Get the error code for this exception. Currently valid values are
96 * available as constants within this class. These values are:
98 * UNKNOWN_ERROR (1000)
99 * USER_DELETED_RECENTLY (1100)
100 * USER_SUSPENDED (1101)
101 * DOMAIN_USER_LIMIT_EXCEEDED (1200)
102 * DOMAIN_ALIAS_LIMIT_EXCEEDED (1201)
103 * DOMAIN_SUSPENDED (1202)
104 * DOMAIN_FEATURE_UNAVAILABLE (1203)
105 * ENTITY_EXISTS (1300)
106 * ENTITY_DOES_NOT_EXIST (1301)
107 * ENTITY_NAME_IS_RESERVED (1302)
108 * ENTITY_NAME_NOT_VALID (1303)
109 * INVALID_GIVEN_NAME (1400)
110 * INVALID_FAMILY_NAME (1401)
111 * INVALID_PASSWORD (1402)
112 * INVALID_USERNAME (1403)
113 * INVALID_HASH_FUNCTION_NAME (1404)
114 * INVALID_HASH_DIGEST_LENGTH (1405)
115 * INVALID_EMAIL_ADDRESS (1406)
116 * INVALID_QUERY_PARAMETER_VALUE (1407)
117 * TOO_MANY_RECIPIENTS_ON_EMAIL_LIST (1500)
119 * Numbers in parenthesis indicate the actual integer value of the
120 * constant. This list should not be treated as exhaustive, as additional
121 * error codes may be added at any time.
123 * For more information about these codes and their meaning, please
124 * see Appendix D of the Google Apps Provisioning API Reference.
126 * @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
128 * @return integer The error code returned by the Google Apps server.
130 public function getErrorCode() {
131 return $this->_errorCode
;
135 * Set human-readable text describing the reason this exception occurred.
138 * @param string $value The reason this exception occurred.
140 public function setReason($value) {
141 $this->_reason
= $value;
145 * Get human-readable text describing the reason this exception occurred.
148 * @return string The reason this exception occurred.
150 public function getReason() {
151 return $this->_reason
;
155 * Set the invalid input which caused this exception.
157 * @see getInvalidInput
158 * @param string $value The invalid input that triggered this exception.
160 public function setInvalidInput($value) {
161 $this->_invalidInput
= $value;
165 * Set the invalid input which caused this exception.
167 * @see setInvalidInput
168 * @return string The reason this exception occurred.
170 public function getInvalidInput() {
171 return $this->_invalidInput
;
175 * Retrieves a DOMElement which corresponds to this element and all
176 * child properties. This is used to build an entry back into a DOM
177 * and eventually XML text for application storage/persistence.
179 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
180 * @return DOMElement The DOMElement representing this element and all
183 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
185 $element = parent
::getDOM($doc, $majorVersion, $minorVersion);
186 if ($this->_errorCode
!== null) {
187 $element->setAttribute('errorCode', $this->_errorCode
);
189 if ($this->_reason
!== null) {
190 $element->setAttribute('reason', $this->_reason
);
192 if ($this->_invalidInput
!== null) {
193 $element->setAttribute('invalidInput', $this->_invalidInput
);
199 * Given a DOMNode representing an attribute, tries to map the data into
200 * instance members. If no mapping is defined, the name and value are
201 * stored in an array.
203 * @param DOMNode $attribute The DOMNode attribute needed to be handled
205 protected function takeAttributeFromDOM($attribute)
207 switch ($attribute->localName
) {
209 $this->_errorCode
= $attribute->nodeValue
;
212 $this->_reason
= $attribute->nodeValue
;
215 $this->_invalidInput
= $attribute->nodeValue
;
218 parent
::takeAttributeFromDOM($attribute);
223 * Get a human readable version of this exception.
227 public function __toString() {
228 return "Error " . $this->getErrorCode() . ": " . $this->getReason() .
229 "\n\tInvalid Input: \"" . $this->getInvalidInput() . "\"";