File indexing completed on 2025-01-26 05:25:26
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 SimpleDb 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 */ 0021 0022 /** 0023 * @see Zend_Http_Response 0024 */ 0025 // require_once 'Zend/Http/Response.php'; 0026 0027 /** @see Zend_Xml_Security */ 0028 // require_once 'Zend/Xml/Security.php'; 0029 0030 /** 0031 * @category Zend 0032 * @package Zend_Service_Amazon 0033 * @subpackage SimpleDb 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Service_Amazon_SimpleDb_Response 0038 { 0039 /** 0040 * XML namespace used for SimpleDB responses. 0041 */ 0042 protected $_xmlNamespace = 'http://sdb.amazonaws.com/doc/2009-04-15/'; 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 SimpleDB response object 0083 * 0084 * @param Zend_Http_Response $httpResponse the HTTP response. 0085 * @return void 0086 */ 0087 public function __construct(Zend_Http_Response $httpResponse) 0088 { 0089 $this->_httpResponse = $httpResponse; 0090 } 0091 0092 /** 0093 * Gets the XPath object for this response 0094 * 0095 * @return DOMXPath the XPath object for response. 0096 */ 0097 public function getXPath() 0098 { 0099 if ($this->_xpath === null) { 0100 $document = $this->getDocument(); 0101 if ($document === false) { 0102 $this->_xpath = false; 0103 } else { 0104 $this->_xpath = new DOMXPath($document); 0105 $this->_xpath->registerNamespace('sdb', 0106 $this->getNamespace()); 0107 } 0108 } 0109 0110 return $this->_xpath; 0111 } 0112 0113 /** 0114 * Gets the SimpleXML document object for this response 0115 * 0116 * @return SimpleXMLElement 0117 */ 0118 public function getSimpleXMLDocument() 0119 { 0120 try { 0121 $body = $this->_httpResponse->getBody(); 0122 } catch (Zend_Http_Exception $e) { 0123 $body = false; 0124 } 0125 0126 return Zend_Xml_Security::scan($body); 0127 } 0128 0129 /** 0130 * Get HTTP response object 0131 * 0132 * @return Zend_Http_Response 0133 */ 0134 public function getHttpResponse() 0135 { 0136 return $this->_httpResponse; 0137 } 0138 0139 /** 0140 * Gets the document object for this response 0141 * 0142 * @return DOMDocument the DOM Document for this response. 0143 */ 0144 public function getDocument() 0145 { 0146 try { 0147 $body = $this->_httpResponse->getBody(); 0148 } catch (Zend_Http_Exception $e) { 0149 $body = false; 0150 } 0151 0152 if ($this->_document === null) { 0153 if ($body !== false) { 0154 // turn off libxml error handling 0155 $errors = libxml_use_internal_errors(); 0156 0157 $this->_document = new DOMDocument(); 0158 $this->_document = Zend_Xml_Security::scan($body, $this->_document); 0159 0160 // reset libxml error handling 0161 libxml_clear_errors(); 0162 libxml_use_internal_errors($errors); 0163 } else { 0164 $this->_document = false; 0165 } 0166 } 0167 0168 return $this->_document; 0169 } 0170 0171 /** 0172 * Return the current set XML Namespace. 0173 * 0174 * @return string 0175 */ 0176 public function getNamespace() 0177 { 0178 return $this->_xmlNamespace; 0179 } 0180 0181 /** 0182 * Set a new XML Namespace 0183 * 0184 * @param string $namespace 0185 */ 0186 public function setNamespace($namespace) 0187 { 0188 $this->_xmlNamespace = $namespace; 0189 } 0190 }