Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Gdata/Gapps/ServiceException.php
Go to the documentation of this file.
00001 <?php
00002 
00028 require_once 'Zend/Exception.php';
00029 
00033 require_once 'Zend/Gdata/Gapps/Error.php';
00034 
00049 class Zend_Gdata_Gapps_ServiceException extends Zend_Exception
00050 {
00051 
00052     protected $_rootElement = "AppsForYourDomainErrors";
00053 
00059     protected $_errors = array();
00060 
00067     public function __construct($errors = null) {
00068         parent::__construct("Server errors encountered");
00069         if ($errors !== null) {
00070             $this->setErrors($errors);
00071         }
00072     }
00073 
00082     public function addError($error) {
00083         // Make sure that we don't try to index an error that doesn't
00084         // contain an index value.
00085         if ($error->getErrorCode() == null) {
00086             require_once 'Zend/Gdata/App/Exception.php';
00087             throw new Zend_Gdata_App_Exception("Error encountered without corresponding error code.");
00088         }
00089 
00090         $this->_errors[$error->getErrorCode()] = $error;
00091     }
00092 
00102     public function setErrors($array) {
00103         $this->_errors = array();
00104         foreach ($array as $error) {
00105             $this->addError($error);
00106         }
00107     }
00108 
00116     public function getErrors() {
00117         return $this->_errors;
00118     }
00119 
00126     public function getError($errorCode) {
00127         if (array_key_exists($errorCode, $this->_errors)) {
00128             $result = $this->_errors[$errorCode];
00129             return $result;
00130         } else {
00131             return null;
00132         }
00133     }
00134 
00143     public function hasError($errorCode) {
00144         return array_key_exists($errorCode, $this->_errors);
00145     }
00146 
00154     public function importFromString($string) {
00155         if ($string) {
00156             // Check to see if an AppsForYourDomainError exists
00157             //
00158             // track_errors is temporarily enabled so that if an error
00159             // occurs while parsing the XML we can append it to an
00160             // exception by referencing $php_errormsg
00161             @ini_set('track_errors', 1);
00162             $doc = new DOMDocument();
00163             $success = @$doc->loadXML($string);
00164             @ini_restore('track_errors');
00165 
00166             if (!$success) {
00167                 require_once 'Zend/Gdata/App/Exception.php';
00168                 // $php_errormsg is automatically generated by PHP if
00169                 // an error occurs while calling loadXML(), above.
00170                 throw new Zend_Gdata_App_Exception("DOMDocument cannot parse XML: $php_errormsg");
00171             }
00172 
00173             // Ensure that the outermost node is an AppsForYourDomain error.
00174             // If it isn't, something has gone horribly wrong.
00175             $rootElement = $doc->getElementsByTagName($this->_rootElement)->item(0);
00176             if (!$rootElement) {
00177                 require_once 'Zend/Gdata/App/Exception.php';
00178                 throw new Zend_Gdata_App_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
00179             }
00180 
00181             foreach ($rootElement->childNodes as $errorNode) {
00182                 if (!($errorNode instanceof DOMText)) {
00183                     $error = new Zend_Gdata_Gapps_Error();
00184                     $error->transferFromDom($errorNode);
00185                     $this->addError($error);
00186                 }
00187             }
00188             return $this;
00189         } else {
00190             require_once 'Zend/Gdata/App/Exception.php';
00191             throw new Zend_Gdata_App_Exception('XML passed to transferFromXML cannot be null');
00192         }
00193 
00194     }
00195 
00201     public function __toString() {
00202         $result = "The server encountered the following errors processing the request:";
00203         foreach ($this->_errors as $error) {
00204             $result .= "\n" . $error->__toString();
00205         }
00206         return $result;
00207     }
00208 }
 All Data Structures Namespaces Files Functions Variables Enumerations