1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Zend Framework |
---|
5 | * |
---|
6 | * LICENSE |
---|
7 | * |
---|
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. |
---|
15 | * |
---|
16 | * @category Zend |
---|
17 | * @package Zend_Gdata |
---|
18 | * @subpackage Gapps |
---|
19 | * @copyright Copyright (c) 2005-2012 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 24594 2012-01-05 21:27:01Z matthew $ |
---|
22 | */ |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | * Zend_Gdata_App_Base |
---|
27 | */ |
---|
28 | require_once 'Zend/Gdata/App/Base.php'; |
---|
29 | |
---|
30 | /** |
---|
31 | * Gdata Gapps Error class. This class is used to represent errors returned |
---|
32 | * within an AppsForYourDomainErrors message received from the Google Apps |
---|
33 | * servers. |
---|
34 | * |
---|
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. |
---|
38 | * |
---|
39 | * @category Zend |
---|
40 | * @package Zend_Gdata |
---|
41 | * @subpackage Gapps |
---|
42 | * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
---|
43 | * @license http://framework.zend.com/license/new-bsd New BSD License |
---|
44 | */ |
---|
45 | class Zend_Gdata_Gapps_Error extends Zend_Gdata_App_Base |
---|
46 | { |
---|
47 | |
---|
48 | // Error codes as defined at |
---|
49 | // http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d |
---|
50 | |
---|
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; |
---|
71 | |
---|
72 | protected $_errorCode = null; |
---|
73 | protected $_reason = null; |
---|
74 | protected $_invalidInput = null; |
---|
75 | |
---|
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; |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * Set the error code for this exception. For more information about |
---|
86 | * error codes, see getErrorCode. |
---|
87 | * |
---|
88 | * @see getErrorCode |
---|
89 | * @param integer $value The new value for the error code. |
---|
90 | */ |
---|
91 | public function setErrorCode($value) { |
---|
92 | $this->_errorCode = $value; |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * Get the error code for this exception. Currently valid values are |
---|
97 | * available as constants within this class. These values are: |
---|
98 | * |
---|
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) |
---|
119 | * |
---|
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. |
---|
123 | * |
---|
124 | * For more information about these codes and their meaning, please |
---|
125 | * see Appendix D of the Google Apps Provisioning API Reference. |
---|
126 | * |
---|
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 |
---|
128 | * @see setErrorCode |
---|
129 | * @return integer The error code returned by the Google Apps server. |
---|
130 | */ |
---|
131 | public function getErrorCode() { |
---|
132 | return $this->_errorCode; |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | * Set human-readable text describing the reason this exception occurred. |
---|
137 | * |
---|
138 | * @see getReason |
---|
139 | * @param string $value The reason this exception occurred. |
---|
140 | */ |
---|
141 | public function setReason($value) { |
---|
142 | $this->_reason = $value; |
---|
143 | } |
---|
144 | |
---|
145 | /** |
---|
146 | * Get human-readable text describing the reason this exception occurred. |
---|
147 | * |
---|
148 | * @see setReason |
---|
149 | * @return string The reason this exception occurred. |
---|
150 | */ |
---|
151 | public function getReason() { |
---|
152 | return $this->_reason; |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * Set the invalid input which caused this exception. |
---|
157 | * |
---|
158 | * @see getInvalidInput |
---|
159 | * @param string $value The invalid input that triggered this exception. |
---|
160 | */ |
---|
161 | public function setInvalidInput($value) { |
---|
162 | $this->_invalidInput = $value; |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * Set the invalid input which caused this exception. |
---|
167 | * |
---|
168 | * @see setInvalidInput |
---|
169 | * @return string The reason this exception occurred. |
---|
170 | */ |
---|
171 | public function getInvalidInput() { |
---|
172 | return $this->_invalidInput; |
---|
173 | } |
---|
174 | |
---|
175 | /** |
---|
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. |
---|
179 | * |
---|
180 | * @param DOMDocument $doc The DOMDocument used to construct DOMElements |
---|
181 | * @return DOMElement The DOMElement representing this element and all |
---|
182 | * child properties. |
---|
183 | */ |
---|
184 | public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) |
---|
185 | { |
---|
186 | $element = parent::getDOM($doc, $majorVersion, $minorVersion); |
---|
187 | if ($this->_errorCode !== null) { |
---|
188 | $element->setAttribute('errorCode', $this->_errorCode); |
---|
189 | } |
---|
190 | if ($this->_reason !== null) { |
---|
191 | $element->setAttribute('reason', $this->_reason); |
---|
192 | } |
---|
193 | if ($this->_invalidInput !== null) { |
---|
194 | $element->setAttribute('invalidInput', $this->_invalidInput); |
---|
195 | } |
---|
196 | return $element; |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
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. |
---|
203 | * |
---|
204 | * @param DOMNode $attribute The DOMNode attribute needed to be handled |
---|
205 | */ |
---|
206 | protected function takeAttributeFromDOM($attribute) |
---|
207 | { |
---|
208 | switch ($attribute->localName) { |
---|
209 | case 'errorCode': |
---|
210 | $this->_errorCode = $attribute->nodeValue; |
---|
211 | break; |
---|
212 | case 'reason': |
---|
213 | $this->_reason = $attribute->nodeValue; |
---|
214 | break; |
---|
215 | case 'invalidInput': |
---|
216 | $this->_invalidInput = $attribute->nodeValue; |
---|
217 | break; |
---|
218 | default: |
---|
219 | parent::takeAttributeFromDOM($attribute); |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | /** |
---|
224 | * Get a human readable version of this exception. |
---|
225 | * |
---|
226 | * @return string |
---|
227 | */ |
---|
228 | public function __toString() { |
---|
229 | return "Error " . $this->getErrorCode() . ": " . $this->getReason() . |
---|
230 | "\n\tInvalid Input: \"" . $this->getInvalidInput() . "\""; |
---|
231 | } |
---|
232 | |
---|
233 | } |
---|