File indexing completed on 2025-03-02 05:29:46

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Service_Amazon
0017  * @subpackage Ec2
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Http_Response
0025  */
0026 // require_once 'Zend/Http/Response.php';
0027 
0028 /** @see Zend_Xml_Security */
0029 // require_once 'Zend/Xml/Security.php';
0030 
0031 /**
0032  * @category   Zend
0033  * @package    Zend_Service_Amazon
0034  * @subpackage Ec2
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Service_Amazon_Ec2_Response {
0039     /**
0040      * XML namespace used for EC2 responses.
0041      */
0042     protected $_xmlNamespace = 'http://ec2.amazonaws.com/doc/2009-04-04/';
0043 
0044     /**
0045      * The original HTTP response
0046      *
0047      * This contains the response body and headers.
0048      *
0049      * @var Zend_Http_Response
0050      */
0051     private $_httpResponse = null;
0052 
0053     /**
0054      * The response document object
0055      *
0056      * @var DOMDocument
0057      */
0058     private $_document = null;
0059 
0060     /**
0061      * The response XPath
0062      *
0063      * @var DOMXPath
0064      */
0065     private $_xpath = null;
0066 
0067     /**
0068      * Last error code
0069      *
0070      * @var integer
0071      */
0072     private $_errorCode = 0;
0073 
0074     /**
0075      * Last error message
0076      *
0077      * @var string
0078      */
0079     private $_errorMessage = '';
0080 
0081     /**
0082      * Creates a new high-level EC2 response object
0083      *
0084      * @param Zend_Http_Response $httpResponse the HTTP response.
0085      */
0086     public function __construct(Zend_Http_Response $httpResponse)
0087     {
0088         $this->_httpResponse = $httpResponse;
0089     }
0090 
0091     /**
0092      * Gets the XPath object for this response
0093      *
0094      * @return DOMXPath the XPath object for response.
0095      */
0096     public function getXPath()
0097     {
0098         if ($this->_xpath === null) {
0099             $document = $this->getDocument();
0100             if ($document === false) {
0101                 $this->_xpath = false;
0102             } else {
0103                 $this->_xpath = new DOMXPath($document);
0104                 $this->_xpath->registerNamespace('ec2',
0105                     $this->getNamespace());
0106             }
0107         }
0108 
0109         return $this->_xpath;
0110     }
0111 
0112     /**
0113      * Gets the document object for this response
0114      *
0115      * @return DOMDocument the DOM Document for this response.
0116      */
0117     public function getDocument()
0118     {
0119         try {
0120             $body = $this->_httpResponse->getBody();
0121         } catch (Zend_Http_Exception $e) {
0122             $body = false;
0123         }
0124         
0125         if ($this->_document === null) {
0126             if ($body !== false) {
0127                 // turn off libxml error handling
0128                 $errors = libxml_use_internal_errors();
0129 
0130                 $this->_document = new DOMDocument();
0131                 $this->_document = Zend_Xml_Security::scan($body, $this->_document);
0132 
0133                 // reset libxml error handling
0134                 libxml_clear_errors();
0135                 libxml_use_internal_errors($errors);
0136             } else {
0137                 $this->_document = false;
0138             }
0139         }
0140 
0141         return $this->_document;
0142     }
0143 
0144     /**
0145      * Return the current set XML Namespace.
0146      *
0147      * @return string
0148      */
0149     public function getNamespace()
0150     {
0151         return $this->_xmlNamespace;
0152     }
0153 
0154     /**
0155      * Set a new XML Namespace
0156      *
0157      * @param string $namespace
0158      */
0159     public function setNamespace($namespace)
0160     {
0161         $this->_xmlNamespace = $namespace;
0162     }
0163 
0164 }