Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
4
 
5
// LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{
6
 
7
/**
8
* +-----------------------------------------------------------------------------+
9
* | Copyright (c) 2004-2006 Sergio Goncalves Carvalho                                |
10
* +-----------------------------------------------------------------------------+
11
* | This file is part of XML_RPC2.                                              |
12
* |                                                                             |
13
* | XML_RPC2 is free software; you can redistribute it and/or modify            |
14
* | it under the terms of the GNU Lesser General Public License as published by |
15
* | the Free Software Foundation; either version 2.1 of the License, or         |
16
* | (at your option) any later version.                                         |
17
* |                                                                             |
18
* | XML_RPC2 is distributed in the hope that it will be useful,                 |
19
* | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
20
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
21
* | GNU Lesser General Public License for more details.                         |
22
* |                                                                             |
23
* | You should have received a copy of the GNU Lesser General Public License    |
24
* | along with XML_RPC2; if not, write to the Free Software                     |
25
* | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA                    |
26
* | 02111-1307 USA                                                              |
27
* +-----------------------------------------------------------------------------+
28
* | Author: Sergio Carvalho <sergio.carvalho@portugalmail.com>                  |
29
* +-----------------------------------------------------------------------------+
30
*
31
* @category   XML
32
* @package    XML_RPC2
33
* @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>
34
* @copyright  2004-2006 Sergio Carvalho
35
* @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
36
* @version    CVS: $Id: Client.php 308706 2011-02-26 17:02:48Z sergiosgc $
37
* @link       http://pear.php.net/package/XML_RPC2
38
*/
39
 
40
// }}}
41
 
42
// dependencies {{{
43
require_once 'XML/RPC2/Exception.php';
44
require_once 'XML/RPC2/Client.php';
45
require_once 'XML/RPC2/Util/HTTPRequest.php';
46
//}}}
47
 
48
/**
49
 * XML_RPC client backend class. This backend class uses the XMLRPCext extension to execute the call.
50
 *
51
 * @category   XML
52
 * @package    XML_RPC2
53
 * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>
54
 * @copyright  2004-2006 Sergio Carvalho
55
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
56
 * @link       http://pear.php.net/package/XML_RPC2
57
 */
58
class XML_RPC2_Backend_Xmlrpcext_Client extends XML_RPC2_Client
59
{
60
 
61
    // {{{ constructor
62
 
63
    /**
64
     * Construct a new XML_RPC2_Client PHP Backend.
65
     *
66
     * A URI must be provided (e.g. http://xmlrpc.example.com/1.0/).
67
     * Optionally, some options may be set.
68
     *
69
     * @param string URI for the XML-RPC server
70
     * @param array (optional) Associative array of options
71
     */
72
    public function __construct($uri, $options = array())
73
    {
74
        parent::__construct($uri, $options);
75
    }
76
 
77
    // }}}
78
    // {{{ __call()
79
 
80
    /**
81
     * __call Catchall. This method catches remote method calls and provides for remote forwarding.
82
     *
83
     * If the parameters are native types, this method will use XML_RPC_Value::createFromNative to
84
     * convert it into an XML-RPC type. Whenever a parameter is already an instance of XML_RPC_Value
85
     * it will be used as provided. It follows that, in situations when XML_RPC_Value::createFromNative
86
     * proves inacurate -- as when encoding DateTime values -- you should present an instance of
87
     * XML_RPC_Value in lieu of the native parameter.
88
     *
89
     * @param   string      Method name
90
     * @param   array       Parameters
91
     * @return  mixed       The call result, already decoded into native types
92
     */
93
    public function __call($methodName, $parameters)
94
    {
95
        $tmp = xmlrpc_encode_request($this->prefix . $methodName, $parameters, array('escaping' => $this->escaping, 'encoding' => $this->encoding));
96
        if ($this->uglyStructHack) {
97
            // ugly hack because of http://bugs.php.net/bug.php?id=21949
98
            // see XML_RPC2_Backend_Xmlrpcext_Value::createFromNative() from more infos
99
            $request = preg_replace('~<name>xml_rpc2_ugly_struct_hack_(.*)</name>~', '<name>\1</name>', $tmp);
100
        } else {
101
            $request = $tmp;
102
        }
103
        $uri = $this->uri;
104
        $options = array(
105
            'encoding' => $this->encoding,
106
            'proxy' => $this->proxy,
107
            'sslverify' => $this->sslverify,
108
            'connectionTimeout' => $this->connectionTimeout
109
        );
110
        if (isset($this->httpRequest)) $options['httpRequest'] = $this->httpRequest;
111
        $httpRequest = new XML_RPC2_Util_HTTPRequest($uri, $options);
112
        $httpRequest->setPostData($request);
113
        $httpRequest->sendRequest();
114
        $body = $httpRequest->getBody();
115
        if ($this->debug) {
116
            XML_RPC2_ClientHelper::printPreParseDebugInfo($request, $body);
117
        }
118
        $result = xmlrpc_decode($body, $this->encoding);
119
        /* Commented due to change in behaviour from xmlrpc_decode. It does not return faults now
120
        if ($result === false || is_null($result)) {
121
            if ($this->debug) {
122
                print "XML_RPC2_Exception : unable to decode response !";
123
            }
124
            throw new XML_RPC2_Exception('Unable to decode response');
125
        }
126
        */
127
        if (is_array($result) && xmlrpc_is_fault($result)) {
128
            if ($this->debug) {
129
                print "XML_RPC2_FaultException(${result['faultString']}, ${result['faultCode']})";
130
            }
131
            throw new XML_RPC2_FaultException($result['faultString'], $result['faultCode']);
132
        }
133
        if ($this->debug) {
134
            XML_RPC2_ClientHelper::printPostRequestDebugInformation($result);
135
        }
136
        return $result;
137
    }
138
 
139
    // }}}
140
 
141
}
142
 
143
?>