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.
16
* @package Zend_Service
17
* @subpackage Nirvanix
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
23
* This class decorates a SimpleXMLElement parsed from a Nirvanix web service
24
* response. It is primarily exists to provide a convenience feature that
25
* throws an exception when <ResponseCode> contains an error.
28
* @package Zend_Service
29
* @subpackage Nirvanix
30
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
31
* @license http://framework.zend.com/license/new-bsd New BSD License
33
class Zend_Service_Nirvanix_Response
36
* SimpleXMLElement parsed from Nirvanix web service response.
38
* @var SimpleXMLElement
43
* Class constructor. Parse the XML response from a Nirvanix method
44
* call into a decorated SimpleXMLElement element.
46
* @param string $xml XML response string from Nirvanix
47
* @throws Zend_Service_Nirvanix_Exception
49
public function __construct($xml)
51
$this->_sxml = @simplexml_load_string($xml);
53
if (! $this->_sxml instanceof SimpleXMLElement) {
54
$this->_throwException("XML could not be parsed from response: $xml");
57
$name = $this->_sxml->getName();
58
if ($name != 'Response') {
59
$this->_throwException("Expected XML element Response, got $name");
62
$code = (int)$this->_sxml->ResponseCode;
64
$msg = (string)$this->_sxml->ErrorMessage;
65
$this->_throwException($msg, $code);
70
* Return the SimpleXMLElement representing this response
73
* @return SimpleXMLElement
75
public function getSxml()
81
* Delegate undefined properties to the decorated SimpleXMLElement.
83
* @param string $offset Undefined property name
86
public function __get($offset)
88
return $this->_sxml->$offset;
92
* Delegate undefined methods to the decorated SimpleXMLElement.
94
* @param string $offset Underfined method name
95
* @param array $args Method arguments
98
public function __call($method, $args)
100
return call_user_func_array(array($this->_sxml, $method), $args);
104
* Throw an exception. This method exists to only contain the
105
* lazy-require() of the exception class.
107
* @param string $message Error message
108
* @param integer $code Error code
109
* @throws Zend_Service_Nirvanix_Exception
112
protected function _throwException($message, $code = null)
115
* @see Zend_Service_Nirvanix_Exception
117
require_once 'Zend/Service/Nirvanix/Exception.php';
119
throw new Zend_Service_Nirvanix_Exception($message, $code);