~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Service/Nirvanix/Response.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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
 
20
 */
 
21
 
 
22
/**
 
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.
 
26
 *
 
27
 * @category   Zend
 
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
 
32
 */
 
33
class Zend_Service_Nirvanix_Response
 
34
{
 
35
    /**
 
36
     * SimpleXMLElement parsed from Nirvanix web service response.
 
37
     * 
 
38
     * @var SimpleXMLElement
 
39
     */
 
40
    protected $_sxml;
 
41
    
 
42
    /**
 
43
     * Class constructor.  Parse the XML response from a Nirvanix method
 
44
     * call into a decorated SimpleXMLElement element.
 
45
     *
 
46
     * @param string $xml  XML response string from Nirvanix
 
47
     * @throws Zend_Service_Nirvanix_Exception
 
48
     */
 
49
    public function __construct($xml)
 
50
    {
 
51
        $this->_sxml = @simplexml_load_string($xml);
 
52
 
 
53
        if (! $this->_sxml instanceof SimpleXMLElement) {
 
54
            $this->_throwException("XML could not be parsed from response: $xml");
 
55
        }
 
56
 
 
57
        $name = $this->_sxml->getName();
 
58
        if ($name != 'Response') {
 
59
            $this->_throwException("Expected XML element Response, got $name");
 
60
        }
 
61
        
 
62
        $code = (int)$this->_sxml->ResponseCode;
 
63
        if ($code != 0) {
 
64
            $msg = (string)$this->_sxml->ErrorMessage;
 
65
            $this->_throwException($msg, $code);
 
66
        }
 
67
    }
 
68
 
 
69
    /**
 
70
     * Return the SimpleXMLElement representing this response
 
71
     * for direct access.
 
72
     *
 
73
     * @return SimpleXMLElement
 
74
     */
 
75
    public function getSxml()
 
76
    {
 
77
        return $this->_sxml;
 
78
    }
 
79
 
 
80
    /**
 
81
     * Delegate undefined properties to the decorated SimpleXMLElement.
 
82
     *
 
83
     * @param  string  $offset  Undefined property name
 
84
     * @return mixed
 
85
     */
 
86
    public function __get($offset) 
 
87
    {
 
88
        return $this->_sxml->$offset;
 
89
    }
 
90
 
 
91
    /**
 
92
     * Delegate undefined methods to the decorated SimpleXMLElement.
 
93
     *
 
94
     * @param  string  $offset  Underfined method name
 
95
     * @param  array   $args    Method arguments
 
96
     * @return mixed
 
97
     */
 
98
    public function __call($method, $args)
 
99
    {
 
100
        return call_user_func_array(array($this->_sxml, $method), $args);
 
101
    }
 
102
 
 
103
    /**
 
104
     * Throw an exception.  This method exists to only contain the
 
105
     * lazy-require() of the exception class.
 
106
     * 
 
107
     * @param  string   $message  Error message
 
108
     * @param  integer  $code     Error code
 
109
     * @throws Zend_Service_Nirvanix_Exception
 
110
     * @return void
 
111
     */
 
112
    protected function _throwException($message, $code = null)
 
113
    {
 
114
        /**
 
115
         * @see Zend_Service_Nirvanix_Exception
 
116
         */
 
117
        require_once 'Zend/Service/Nirvanix/Exception.php';        
 
118
 
 
119
        throw new Zend_Service_Nirvanix_Exception($message, $code);
 
120
    }
 
121
 
 
122
}