|
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 license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Service_Amazon |
|
17 * @subpackage SimpleDb |
|
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 */ |
|
21 |
|
22 /** |
|
23 * @see Zend_Http_Response |
|
24 */ |
|
25 require_once 'Zend/Http/Response.php'; |
|
26 |
|
27 /** |
|
28 * @category Zend |
|
29 * @package Zend_Service_Amazon |
|
30 * @subpackage SimpleDb |
|
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
33 */ |
|
34 class Zend_Service_Amazon_SimpleDb_Response |
|
35 { |
|
36 /** |
|
37 * XML namespace used for SimpleDB responses. |
|
38 */ |
|
39 protected $_xmlNamespace = 'http://sdb.amazonaws.com/doc/2009-04-15/'; |
|
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 SimpleDB response object |
|
80 * |
|
81 * @param Zend_Http_Response $httpResponse the HTTP response. |
|
82 * @return void |
|
83 */ |
|
84 public function __construct(Zend_Http_Response $httpResponse) |
|
85 { |
|
86 $this->_httpResponse = $httpResponse; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Gets the XPath object for this response |
|
91 * |
|
92 * @return DOMXPath the XPath object for response. |
|
93 */ |
|
94 public function getXPath() |
|
95 { |
|
96 if ($this->_xpath === null) { |
|
97 $document = $this->getDocument(); |
|
98 if ($document === false) { |
|
99 $this->_xpath = false; |
|
100 } else { |
|
101 $this->_xpath = new DOMXPath($document); |
|
102 $this->_xpath->registerNamespace('sdb', |
|
103 $this->getNamespace()); |
|
104 } |
|
105 } |
|
106 |
|
107 return $this->_xpath; |
|
108 } |
|
109 |
|
110 /** |
|
111 * Gets the SimpleXML document object for this response |
|
112 * |
|
113 * @return SimpleXMLElement |
|
114 */ |
|
115 public function getSimpleXMLDocument() |
|
116 { |
|
117 try { |
|
118 $body = $this->_httpResponse->getBody(); |
|
119 } catch (Zend_Http_Exception $e) { |
|
120 $body = false; |
|
121 } |
|
122 |
|
123 |
|
124 return simplexml_load_string($body); |
|
125 } |
|
126 |
|
127 /** |
|
128 * Get HTTP response object |
|
129 * |
|
130 * @return Zend_Http_Response |
|
131 */ |
|
132 public function getHttpResponse() |
|
133 { |
|
134 return $this->_httpResponse; |
|
135 } |
|
136 |
|
137 /** |
|
138 * Gets the document object for this response |
|
139 * |
|
140 * @return DOMDocument the DOM Document for this response. |
|
141 */ |
|
142 public function getDocument() |
|
143 { |
|
144 try { |
|
145 $body = $this->_httpResponse->getBody(); |
|
146 } catch (Zend_Http_Exception $e) { |
|
147 $body = false; |
|
148 } |
|
149 |
|
150 if ($this->_document === null) { |
|
151 if ($body !== false) { |
|
152 // turn off libxml error handling |
|
153 $errors = libxml_use_internal_errors(); |
|
154 |
|
155 $this->_document = new DOMDocument(); |
|
156 if (!$this->_document->loadXML($body)) { |
|
157 $this->_document = false; |
|
158 } |
|
159 |
|
160 // reset libxml error handling |
|
161 libxml_clear_errors(); |
|
162 libxml_use_internal_errors($errors); |
|
163 } else { |
|
164 $this->_document = false; |
|
165 } |
|
166 } |
|
167 |
|
168 return $this->_document; |
|
169 } |
|
170 |
|
171 /** |
|
172 * Return the current set XML Namespace. |
|
173 * |
|
174 * @return string |
|
175 */ |
|
176 public function getNamespace() |
|
177 { |
|
178 return $this->_xmlNamespace; |
|
179 } |
|
180 |
|
181 /** |
|
182 * Set a new XML Namespace |
|
183 * |
|
184 * @param string $namespace |
|
185 */ |
|
186 public function setNamespace($namespace) |
|
187 { |
|
188 $this->_xmlNamespace = $namespace; |
|
189 } |
|
190 } |