Esempio n. 1
0
 /**
  * Add a single Error object to the list of errors received by the
  * server.
  *
  * @param \ZendGData\GApps\Error $error An instance of an error returned
  *          by the server. The error's errorCode must be set.
  * @throws \ZendGData\App\Exception
  */
 public function addError($error)
 {
     // Make sure that we don't try to index an error that doesn't
     // contain an index value.
     if ($error->getErrorCode() == null) {
         throw new App\Exception("Error encountered without corresponding error code.");
     }
     $this->_errors[$error->getErrorCode()] = $error;
 }
Esempio n. 2
0
 /**
  * Import an AppsForYourDomain error from XML.
  *
  * @param string $string The XML data to be imported
  * @return \ZendGData\GApps\ServiceException Provides a fluent interface.
  * @throws \ZendGData\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
         // exception by referencing $php_errormsg
         ErrorHandler::start(E_WARNING);
         ini_set('track_errors', 1);
         $doc = new \DOMDocument();
         $success = $doc->loadXML($string);
         ini_restore('track_errors');
         ErrorHandler::stop();
         if (!$success) {
             // $php_errormsg is automatically generated by PHP if
             // an error occurs while calling loadXML(), above.
             throw new App\Exception("DOMDocument cannot parse XML: {$php_errormsg}");
         }
         // 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) {
             throw new App\Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
         }
         foreach ($rootElement->childNodes as $errorNode) {
             if (!$errorNode instanceof \DOMText) {
                 $error = new Error();
                 $error->transferFromDom($errorNode);
                 $this->addError($error);
             }
         }
         return $this;
     } else {
         throw new App\Exception('XML passed to transferFromXML cannot be null');
     }
 }