| 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/Util/HTTPRequest.php';
|
|
|
45 |
require_once 'XML/RPC2/Value.php';
|
|
|
46 |
require_once 'XML/RPC2/Client.php';
|
|
|
47 |
require_once 'XML/RPC2/Backend/Php/Request.php';
|
|
|
48 |
require_once 'XML/RPC2/Backend/Php/Response.php';
|
|
|
49 |
// }}}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* XML_RPC client backend class. This is the default, all-php XML_RPC client backend.
|
|
|
53 |
*
|
|
|
54 |
* This backend does not require the xmlrpc extension to be compiled in. It implements
|
|
|
55 |
* XML_RPC based on the always present DOM and SimpleXML PHP5 extensions.
|
|
|
56 |
*
|
|
|
57 |
* @category XML
|
|
|
58 |
* @package XML_RPC2
|
|
|
59 |
* @author Sergio Carvalho <sergio.carvalho@portugalmail.com>
|
|
|
60 |
* @copyright 2004-2006 Sergio Carvalho
|
|
|
61 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
|
|
62 |
* @link http://pear.php.net/package/XML_RPC2
|
|
|
63 |
*/
|
|
|
64 |
class XML_RPC2_Backend_Php_Client extends XML_RPC2_Client
|
|
|
65 |
{
|
|
|
66 |
|
|
|
67 |
// {{{ constructor
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Construct a new XML_RPC2_Client PHP Backend.
|
|
|
71 |
*
|
|
|
72 |
* To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/).
|
|
|
73 |
* Optionally, some options may be set
|
|
|
74 |
*
|
|
|
75 |
* @param string URI for the XML-RPC server
|
|
|
76 |
* @param array (optional) Associative array of options
|
|
|
77 |
*/
|
|
|
78 |
public function __construct($uri, $options = array())
|
|
|
79 |
{
|
|
|
80 |
parent::__construct($uri, $options);
|
|
|
81 |
if ($this->encoding != 'utf-8') throw new XML_RPC2_Exception('XML_RPC2_Backend_Php does not support any encoding other than utf-8, due to a simplexml limitation');
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
// }}}
|
|
|
85 |
// {{{ __call()
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* __call Catchall. This method catches remote method calls and provides for remote forwarding.
|
|
|
89 |
*
|
|
|
90 |
* If the parameters are native types, this method will use XML_RPC_Value::createFromNative to
|
|
|
91 |
* convert it into an XML-RPC type. Whenever a parameter is already an instance of XML_RPC_Value
|
|
|
92 |
* it will be used as provided. It follows that, in situations when XML_RPC_Value::createFromNative
|
|
|
93 |
* proves inacurate -- as when encoding DateTime values -- you should present an instance of
|
|
|
94 |
* XML_RPC_Value in lieu of the native parameter.
|
|
|
95 |
*
|
|
|
96 |
* @param string Method name
|
|
|
97 |
* @param array Parameters
|
|
|
98 |
* @return mixed The call result, already decoded into native types
|
|
|
99 |
*/
|
|
|
100 |
public function __call($methodName, $parameters)
|
|
|
101 |
{
|
|
|
102 |
$request = new XML_RPC2_Backend_Php_Request($this->prefix . $methodName, $this->encoding);
|
|
|
103 |
$request->setParameters($parameters);
|
|
|
104 |
$request = $request->encode();
|
|
|
105 |
$uri = $this->uri;
|
|
|
106 |
$options = array(
|
|
|
107 |
'encoding' => $this->encoding,
|
|
|
108 |
'proxy' => $this->proxy,
|
|
|
109 |
'sslverify' => $this->sslverify,
|
|
|
110 |
'connectionTimeout' => $this->connectionTimeout
|
|
|
111 |
);
|
|
|
112 |
if (isset($this->httpRequest)) $options['httpRequest'] = $this->httpRequest;
|
|
|
113 |
$httpRequest = new XML_RPC2_Util_HTTPRequest($uri, $options);
|
|
|
114 |
$httpRequest->setPostData($request);
|
|
|
115 |
$httpRequest->sendRequest();
|
|
|
116 |
$body = $httpRequest->getBody();
|
|
|
117 |
if ($this->debug) {
|
|
|
118 |
XML_RPC2_ClientHelper::printPreParseDebugInfo($request, $body);
|
|
|
119 |
}
|
|
|
120 |
try {
|
|
|
121 |
$document = new SimpleXMLElement($body);
|
|
|
122 |
$result = XML_RPC2_Backend_Php_Response::decode($document);
|
|
|
123 |
} catch (XML_RPC2_Exception $e) {
|
|
|
124 |
if ($this->debug) {
|
|
|
125 |
if (get_class($e)=='XML_RPC2_FaultException') {
|
|
|
126 |
print "XML_RPC2_FaultException #" . $e->getFaultCode() . " : " . $e->getMessage();
|
|
|
127 |
} else {
|
|
|
128 |
print get_class($e) . " : " . $e->getMessage();
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
throw $e;
|
|
|
132 |
}
|
|
|
133 |
if ($this->debug) {
|
|
|
134 |
XML_RPC2_ClientHelper::printPostRequestDebugInformation($result);
|
|
|
135 |
}
|
|
|
136 |
return $result;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
// }}}
|
|
|
140 |
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
?>
|