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
21 * @version $Id: Error.php 16971 2009-07-22 18:05:45Z mikaelkael $
28 require_once 'Zend/Gdata/App/Base.php';
31 * Gdata Gapps Error class. This class is used to represent errors returned
32 * within an AppsForYourDomainErrors message received from the Google Apps
35 * Several different errors may be represented by this class, determined by
36 * the error code returned by the server. For a list of error codes
37 * available at the time of this writing, see getErrorCode.
42 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
43 * @license http://framework.zend.com/license/new-bsd New BSD License
45 class Zend_Gdata_Gapps_Error
extends Zend_Gdata_App_Base
48 // Error codes as defined at
49 // http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d
51 const UNKNOWN_ERROR
= 1000;
52 const USER_DELETED_RECENTLY
= 1100;
53 const USER_SUSPENDED
= 1101;
54 const DOMAIN_USER_LIMIT_EXCEEDED
= 1200;
55 const DOMAIN_ALIAS_LIMIT_EXCEEDED
= 1201;
56 const DOMAIN_SUSPENDED
= 1202;
57 const DOMAIN_FEATURE_UNAVAILABLE
= 1203;
58 const ENTITY_EXISTS
= 1300;
59 const ENTITY_DOES_NOT_EXIST
= 1301;
60 const ENTITY_NAME_IS_RESERVED
= 1302;
61 const ENTITY_NAME_NOT_VALID
= 1303;
62 const INVALID_GIVEN_NAME
= 1400;
63 const INVALID_FAMILY_NAME
= 1401;
64 const INVALID_PASSWORD
= 1402;
65 const INVALID_USERNAME
= 1403;
66 const INVALID_HASH_FUNCTION_NAME
= 1404;
67 const INVALID_HASH_DIGEST_LENGTH
= 1405;
68 const INVALID_EMAIL_ADDRESS
= 1406;
69 const INVALID_QUERY_PARAMETER_VALUE
= 1407;
70 const TOO_MANY_RECIPIENTS_ON_EMAIL_LIST
= 1500;
72 protected $_errorCode = null;
73 protected $_reason = null;
74 protected $_invalidInput = null;
76 public function __construct($errorCode = null, $reason = null,
77 $invalidInput = null) {
78 parent
::__construct("Google Apps error received: $errorCode ($reason)");
79 $this->_errorCode
= $errorCode;
80 $this->_reason
= $reason;
81 $this->_invalidInput
= $invalidInput;
85 * Set the error code for this exception. For more information about
86 * error codes, see getErrorCode.
89 * @param integer $value The new value for the error code.
91 public function setErrorCode($value) {
92 $this->_errorCode
= $value;
96 * Get the error code for this exception. Currently valid values are
97 * available as constants within this class. These values are:
99 * UNKNOWN_ERROR (1000)
100 * USER_DELETED_RECENTLY (1100)
101 * USER_SUSPENDED (1101)
102 * DOMAIN_USER_LIMIT_EXCEEDED (1200)
103 * DOMAIN_ALIAS_LIMIT_EXCEEDED (1201)
104 * DOMAIN_SUSPENDED (1202)
105 * DOMAIN_FEATURE_UNAVAILABLE (1203)
106 * ENTITY_EXISTS (1300)
107 * ENTITY_DOES_NOT_EXIST (1301)
108 * ENTITY_NAME_IS_RESERVED (1302)
109 * ENTITY_NAME_NOT_VALID (1303)
110 * INVALID_GIVEN_NAME (1400)
111 * INVALID_FAMILY_NAME (1401)
112 * INVALID_PASSWORD (1402)
113 * INVALID_USERNAME (1403)
114 * INVALID_HASH_FUNCTION_NAME (1404)
115 * INVALID_HASH_DIGEST_LENGTH (1405)
116 * INVALID_EMAIL_ADDRESS (1406)
117 * INVALID_QUERY_PARAMETER_VALUE (1407)
118 * TOO_MANY_RECIPIENTS_ON_EMAIL_LIST (1500)
120 * Numbers in parenthesis indicate the actual integer value of the
121 * constant. This list should not be treated as exhaustive, as additional
122 * error codes may be added at any time.
124 * For more information about these codes and their meaning, please
125 * see Appendix D of the Google Apps Provisioning API Reference.
127 * @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
129 * @return integer The error code returned by the Google Apps server.
131 public function getErrorCode() {
132 return $this->_errorCode
;
136 * Set human-readable text describing the reason this exception occurred.
139 * @param string $value The reason this exception occurred.
141 public function setReason($value) {
142 $this->_reason
= $value;
146 * Get human-readable text describing the reason this exception occurred.
149 * @return string The reason this exception occurred.
151 public function getReason() {
152 return $this->_reason
;
156 * Set the invalid input which caused this exception.
158 * @see getInvalidInput
159 * @param string $value The invalid input that triggered this exception.
161 public function setInvalidInput($value) {
162 $this->_invalidInput
= $value;
166 * Set the invalid input which caused this exception.
168 * @see setInvalidInput
169 * @return string The reason this exception occurred.
171 public function getInvalidInput() {
172 return $this->_invalidInput
;
176 * Retrieves a DOMElement which corresponds to this element and all
177 * child properties. This is used to build an entry back into a DOM
178 * and eventually XML text for application storage/persistence.
180 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
181 * @return DOMElement The DOMElement representing this element and all
184 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
186 $element = parent
::getDOM($doc, $majorVersion, $minorVersion);
187 if ($this->_errorCode
!== null) {
188 $element->setAttribute('errorCode', $this->_errorCode
);
190 if ($this->_reason
!== null) {
191 $element->setAttribute('reason', $this->_reason
);
193 if ($this->_invalidInput
!== null) {
194 $element->setAttribute('invalidInput', $this->_invalidInput
);
200 * Given a DOMNode representing an attribute, tries to map the data into
201 * instance members. If no mapping is defined, the name and value are
202 * stored in an array.
204 * @param DOMNode $attribute The DOMNode attribute needed to be handled
206 protected function takeAttributeFromDOM($attribute)
208 switch ($attribute->localName
) {
210 $this->_errorCode
= $attribute->nodeValue
;
213 $this->_reason
= $attribute->nodeValue
;
216 $this->_invalidInput
= $attribute->nodeValue
;
219 parent
::takeAttributeFromDOM($attribute);
224 * Get a human readable version of this exception.
228 public function __toString() {
229 return "Error " . $this->getErrorCode() . ": " . $this->getReason() .
230 "\n\tInvalid Input: \"" . $this->getInvalidInput() . "\"";