[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/Service/Amazon/Ec2/ -> Response.php (source)

   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 [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Service_Amazon
  17   * @subpackage Ec2
  18   * @copyright  Copyright (c) 2005-2010 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  /**
  24   * @see Zend_Http_Response
  25   */
  26  require_once 'Zend/Http/Response.php';
  27  
  28  /**
  29   * @category   Zend
  30   * @package    Zend_Service_Amazon
  31   * @subpackage Ec2
  32   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  34   */
  35  class Zend_Service_Amazon_Ec2_Response {
  36      /**
  37       * XML namespace used for EC2 responses.
  38       */
  39      protected $_xmlNamespace = 'http://ec2.amazonaws.com/doc/2009-04-04/';
  40  
  41      /**
  42       * The original HTTP response
  43       *
  44       * This contains the response body and headers.
  45       *
  46       * @var Zend_Http_Response
  47       */
  48      private $_httpResponse = null;
  49  
  50      /**
  51       * The response document object
  52       *
  53       * @var DOMDocument
  54       */
  55      private $_document = null;
  56  
  57      /**
  58       * The response XPath
  59       *
  60       * @var DOMXPath
  61       */
  62      private $_xpath = null;
  63  
  64      /**
  65       * Last error code
  66       *
  67       * @var integer
  68       */
  69      private $_errorCode = 0;
  70  
  71      /**
  72       * Last error message
  73       *
  74       * @var string
  75       */
  76      private $_errorMessage = '';
  77  
  78      /**
  79       * Creates a new high-level EC2 response object
  80       *
  81       * @param Zend_Http_Response $httpResponse the HTTP response.
  82       */
  83      public function __construct(Zend_Http_Response $httpResponse)
  84      {
  85          $this->_httpResponse = $httpResponse;
  86      }
  87  
  88      /**
  89       * Gets the XPath object for this response
  90       *
  91       * @return DOMXPath the XPath object for response.
  92       */
  93      public function getXPath()
  94      {
  95          if ($this->_xpath === null) {
  96              $document = $this->getDocument();
  97              if ($document === false) {
  98                  $this->_xpath = false;
  99              } else {
 100                  $this->_xpath = new DOMXPath($document);
 101                  $this->_xpath->registerNamespace('ec2',
 102                      $this->getNamespace());
 103              }
 104          }
 105  
 106          return $this->_xpath;
 107      }
 108  
 109      /**
 110       * Gets the document object for this response
 111       *
 112       * @return DOMDocument the DOM Document for this response.
 113       */
 114      public function getDocument()
 115      {
 116          try {
 117              $body = $this->_httpResponse->getBody();
 118          } catch (Zend_Http_Exception $e) {
 119              $body = false;
 120          }
 121  
 122          if ($this->_document === null) {
 123              if ($body !== false) {
 124                  // turn off libxml error handling
 125                  $errors = libxml_use_internal_errors();
 126  
 127                  $this->_document = new DOMDocument();
 128                  if (!$this->_document->loadXML($body)) {
 129                      $this->_document = false;
 130                  }
 131  
 132                  // reset libxml error handling
 133                  libxml_clear_errors();
 134                  libxml_use_internal_errors($errors);
 135              } else {
 136                  $this->_document = false;
 137              }
 138          }
 139  
 140          return $this->_document;
 141      }
 142  
 143      /**
 144       * Return the current set XML Namespace.
 145       *
 146       * @return string
 147       */
 148      public function getNamespace()
 149      {
 150          return $this->_xmlNamespace;
 151      }
 152  
 153      /**
 154       * Set a new XML Namespace
 155       *
 156       * @param string $namespace
 157       */
 158      public function setNamespace($namespace)
 159      {
 160          $this->_xmlNamespace = $namespace;
 161      }
 162  
 163  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1