CommunityID/libs/Zend/Gdata/Gapps/ServiceException.php

209 lines
6.7 KiB
PHP
Raw Normal View History

2019-07-17 20:08:50 +00:00
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
2019-07-17 20:19:00 +00:00
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
2019-07-17 20:08:50 +00:00
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ServiceException.php 18951 2009-11-12 16:26:19Z alexander $
2019-07-17 20:08:50 +00:00
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Zend_Gdata_Gapps_Error
*/
require_once 'Zend/Gdata/Gapps/Error.php';
/**
* Gdata Gapps Exception class. This is thrown when an
* AppsForYourDomainErrors message is received from the Google Apps
2019-07-17 20:08:50 +00:00
* servers.
*
* Several different errors may be represented by this exception. For a list
2019-07-17 20:08:50 +00:00
* of error codes available, see getErrorCode.
*
* @category Zend
* @package Zend_Gdata
2019-07-17 20:16:19 +00:00
* @subpackage Gapps
2019-07-17 20:19:00 +00:00
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
2019-07-17 20:08:50 +00:00
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Gdata_Gapps_ServiceException extends Zend_Exception
{
2019-07-17 20:08:50 +00:00
protected $_rootElement = "AppsForYourDomainErrors";
/**
2019-07-17 20:08:50 +00:00
* Array of Zend_Gdata_Error objects indexed by error code.
*
2019-07-17 20:08:50 +00:00
* @var array
*/
protected $_errors = array();
2019-07-17 20:08:50 +00:00
/**
* Create a new ServiceException.
*
* @return array An array containing a collection of
2019-07-17 20:08:50 +00:00
* Zend_Gdata_Gapps_Error objects.
*/
public function __construct($errors = null) {
parent::__construct("Server errors encountered");
if ($errors !== null) {
$this->setErrors($errors);
}
}
2019-07-17 20:08:50 +00:00
/**
* Add a single Error object to the list of errors received by the
2019-07-17 20:08:50 +00:00
* server.
*
* @param Zend_Gdata_Gapps_Error $error An instance of an error returned
2019-07-17 20:08:50 +00:00
* by the server. The error's errorCode must be set.
* @throws Zend_Gdata_App_Exception
*/
public function addError($error) {
// Make sure that we don't try to index an error that doesn't
2019-07-17 20:08:50 +00:00
// contain an index value.
if ($error->getErrorCode() == null) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("Error encountered without corresponding error code.");
}
2019-07-17 20:08:50 +00:00
$this->_errors[$error->getErrorCode()] = $error;
}
2019-07-17 20:08:50 +00:00
/**
* Set the list of errors as sent by the server inside of an
2019-07-17 20:08:50 +00:00
* AppsForYourDomainErrors tag.
*
* @param array $array An associative array containing a collection of
* Zend_Gdata_Gapps_Error objects. All errors must have their
2019-07-17 20:08:50 +00:00
* errorCode value set.
* @throws Zend_Gdata_App_Exception
*/
public function setErrors($array) {
$this->_errors = array();
foreach ($array as $error) {
$this->addError($error);
}
}
2019-07-17 20:08:50 +00:00
/**
* Get the list of errors as sent by the server inside of an
2019-07-17 20:08:50 +00:00
* AppsForYourDomainErrors tag.
*
* @return array An associative array containing a collection of
2019-07-17 20:08:50 +00:00
* Zend_Gdata_Gapps_Error objects, indexed by error code.
*/
public function getErrors() {
return $this->_errors;
}
2019-07-17 20:08:50 +00:00
/**
* Return the Error object associated with a specific error code.
*
* @return Zend_Gdata_Gapps_Error The Error object requested, or null
2019-07-17 20:08:50 +00:00
* if not found.
*/
public function getError($errorCode) {
if (array_key_exists($errorCode, $this->_errors)) {
$result = $this->_errors[$errorCode];
return $result;
} else {
return null;
}
}
2019-07-17 20:08:50 +00:00
/**
* Check whether or not a particular error code was returned by the
2019-07-17 20:08:50 +00:00
* server.
*
* @param integer $errorCode The error code to check against.
* @return boolean Whether or not the supplied error code was returned
2019-07-17 20:08:50 +00:00
* by the server.
*/
public function hasError($errorCode) {
return array_key_exists($errorCode, $this->_errors);
}
2019-07-17 20:08:50 +00:00
/**
* Import an AppsForYourDomain error from XML.
*
2019-07-17 20:08:50 +00:00
* @param string $string The XML data to be imported
* @return Zend_Gdata_Gapps_ServiceException Provides a fluent interface.
* @throws Zend_Gdata_App_Exception
*/
public function importFromString($string) {
if ($string) {
// Check to see if an AppsForYourDomainError exists
//
// track_errors is temporarily enabled so that if an error
// occurs while parsing the XML we can append it to an
2019-07-17 20:08:50 +00:00
// exception by referencing $php_errormsg
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$success = @$doc->loadXML($string);
@ini_restore('track_errors');
2019-07-17 20:08:50 +00:00
if (!$success) {
require_once 'Zend/Gdata/App/Exception.php';
// $php_errormsg is automatically generated by PHP if
2019-07-17 20:08:50 +00:00
// an error occurs while calling loadXML(), above.
throw new Zend_Gdata_App_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
2019-07-17 20:08:50 +00:00
// Ensure that the outermost node is an AppsForYourDomain error.
// If it isn't, something has gone horribly wrong.
$rootElement = $doc->getElementsByTagName($this->_rootElement)->item(0);
if (!$rootElement) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
}
2019-07-17 20:08:50 +00:00
foreach ($rootElement->childNodes as $errorNode) {
if (!($errorNode instanceof DOMText)) {
$error = new Zend_Gdata_Gapps_Error();
$error->transferFromDom($errorNode);
$this->addError($error);
}
}
return $this;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('XML passed to transferFromXML cannot be null');
}
2019-07-17 20:08:50 +00:00
}
2019-07-17 20:08:50 +00:00
/**
* Get a human readable version of this exception.
*
2019-07-17 20:08:50 +00:00
* @return string
*/
public function __toString() {
$result = "The server encountered the following errors processing the request:";
foreach ($this->_errors as $error) {
$result .= "\n" . $error->__toString();
}
return $result;
}
}