PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/zendframework1/library/Zend/Gdata/Gapps/ServiceException.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 211 lines | 70 code | 21 blank | 120 comment | 10 complexity | e62bc29c1a67ab44455ebc10fb033887 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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Exception
  24. */
  25. #require_once 'Zend/Exception.php';
  26. /**
  27. * Zend_Gdata_Gapps_Error
  28. */
  29. #require_once 'Zend/Gdata/Gapps/Error.php';
  30. /** @see Zend_Xml_Security */
  31. #require_once 'Zend/Xml/Security.php';
  32. /**
  33. * Gdata Gapps Exception class. This is thrown when an
  34. * AppsForYourDomainErrors message is received from the Google Apps
  35. * servers.
  36. *
  37. * Several different errors may be represented by this exception. For a list
  38. * of error codes available, see getErrorCode.
  39. *
  40. * @category Zend
  41. * @package Zend_Gdata
  42. * @subpackage Gapps
  43. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  44. * @license http://framework.zend.com/license/new-bsd New BSD License
  45. */
  46. class Zend_Gdata_Gapps_ServiceException extends Zend_Exception
  47. {
  48. protected $_rootElement = "AppsForYourDomainErrors";
  49. /**
  50. * Array of Zend_Gdata_Error objects indexed by error code.
  51. *
  52. * @var array
  53. */
  54. protected $_errors = array();
  55. /**
  56. * Create a new ServiceException.
  57. *
  58. * @return array An array containing a collection of
  59. * Zend_Gdata_Gapps_Error objects.
  60. */
  61. public function __construct($errors = null) {
  62. parent::__construct("Server errors encountered");
  63. if ($errors !== null) {
  64. $this->setErrors($errors);
  65. }
  66. }
  67. /**
  68. * Add a single Error object to the list of errors received by the
  69. * server.
  70. *
  71. * @param Zend_Gdata_Gapps_Error $error An instance of an error returned
  72. * by the server. The error's errorCode must be set.
  73. * @throws Zend_Gdata_App_Exception
  74. */
  75. public function addError($error) {
  76. // Make sure that we don't try to index an error that doesn't
  77. // contain an index value.
  78. if ($error->getErrorCode() == null) {
  79. #require_once 'Zend/Gdata/App/Exception.php';
  80. throw new Zend_Gdata_App_Exception("Error encountered without corresponding error code.");
  81. }
  82. $this->_errors[$error->getErrorCode()] = $error;
  83. }
  84. /**
  85. * Set the list of errors as sent by the server inside of an
  86. * AppsForYourDomainErrors tag.
  87. *
  88. * @param array $array An associative array containing a collection of
  89. * Zend_Gdata_Gapps_Error objects. All errors must have their
  90. * errorCode value set.
  91. * @throws Zend_Gdata_App_Exception
  92. */
  93. public function setErrors($array) {
  94. $this->_errors = array();
  95. foreach ($array as $error) {
  96. $this->addError($error);
  97. }
  98. }
  99. /**
  100. * Get the list of errors as sent by the server inside of an
  101. * AppsForYourDomainErrors tag.
  102. *
  103. * @return array An associative array containing a collection of
  104. * Zend_Gdata_Gapps_Error objects, indexed by error code.
  105. */
  106. public function getErrors() {
  107. return $this->_errors;
  108. }
  109. /**
  110. * Return the Error object associated with a specific error code.
  111. *
  112. * @return Zend_Gdata_Gapps_Error The Error object requested, or null
  113. * if not found.
  114. */
  115. public function getError($errorCode) {
  116. if (array_key_exists($errorCode, $this->_errors)) {
  117. $result = $this->_errors[$errorCode];
  118. return $result;
  119. } else {
  120. return null;
  121. }
  122. }
  123. /**
  124. * Check whether or not a particular error code was returned by the
  125. * server.
  126. *
  127. * @param integer $errorCode The error code to check against.
  128. * @return boolean Whether or not the supplied error code was returned
  129. * by the server.
  130. */
  131. public function hasError($errorCode) {
  132. return array_key_exists($errorCode, $this->_errors);
  133. }
  134. /**
  135. * Import an AppsForYourDomain error from XML.
  136. *
  137. * @param string $string The XML data to be imported
  138. * @return Zend_Gdata_Gapps_ServiceException Provides a fluent interface.
  139. * @throws Zend_Gdata_App_Exception
  140. */
  141. public function importFromString($string) {
  142. if ($string) {
  143. // Check to see if an AppsForYourDomainError exists
  144. //
  145. // track_errors is temporarily enabled so that if an error
  146. // occurs while parsing the XML we can append it to an
  147. // exception by referencing $php_errormsg
  148. @ini_set('track_errors', 1);
  149. $doc = new DOMDocument();
  150. $doc = @Zend_Xml_Security::scan($string, $doc);
  151. @ini_restore('track_errors');
  152. if (!$doc) {
  153. #require_once 'Zend/Gdata/App/Exception.php';
  154. // $php_errormsg is automatically generated by PHP if
  155. // an error occurs while calling loadXML(), above.
  156. throw new Zend_Gdata_App_Exception("DOMDocument cannot parse XML: $php_errormsg");
  157. }
  158. // Ensure that the outermost node is an AppsForYourDomain error.
  159. // If it isn't, something has gone horribly wrong.
  160. $rootElement = $doc->getElementsByTagName($this->_rootElement)->item(0);
  161. if (!$rootElement) {
  162. #require_once 'Zend/Gdata/App/Exception.php';
  163. throw new Zend_Gdata_App_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
  164. }
  165. foreach ($rootElement->childNodes as $errorNode) {
  166. if (!($errorNode instanceof DOMText)) {
  167. $error = new Zend_Gdata_Gapps_Error();
  168. $error->transferFromDom($errorNode);
  169. $this->addError($error);
  170. }
  171. }
  172. return $this;
  173. } else {
  174. #require_once 'Zend/Gdata/App/Exception.php';
  175. throw new Zend_Gdata_App_Exception('XML passed to transferFromXML cannot be null');
  176. }
  177. }
  178. /**
  179. * Get a human readable version of this exception.
  180. *
  181. * @return string
  182. */
  183. public function __toString() {
  184. $result = "The server encountered the following errors processing the request:";
  185. foreach ($this->_errors as $error) {
  186. $result .= "\n" . $error->__toString();
  187. }
  188. return $result;
  189. }
  190. }