1
|
|
|
<?php |
2
|
|
|
global $AR; |
3
|
|
|
require_once($AR->dir->install."/lib/includes/ripcord/ripcord.php"); |
4
|
|
|
|
5
|
|
|
ar_pinp::allow('ar_connect_xmlrpc'); |
6
|
|
|
ar_pinp::allow('ar_connect_xmlrpcClient'); |
7
|
|
|
ar_pinp::allow('ar_connect_xmlrpcServer'); |
8
|
|
|
|
9
|
|
|
// FIXME: define interfaces |
10
|
|
|
|
11
|
|
|
class ar_connect_xmlrpc extends arBase { |
12
|
|
|
|
13
|
|
|
private static function services( $methods ) { |
14
|
|
|
$result = array(); |
15
|
|
|
foreach ($methods as $methodName => $method) { |
16
|
|
|
if ( !($method instanceof \Closure) ) { |
17
|
|
|
$params = array(); |
18
|
|
|
if (is_array($method)) { |
19
|
|
|
$template = array_shift($method); |
20
|
|
|
$params = $method; |
21
|
|
|
} else { |
22
|
|
|
$template = $method; |
23
|
|
|
} |
24
|
|
|
$result[$methodName] = ar_pinp::getCallback($template, $params); |
25
|
|
|
} else { |
26
|
|
|
$result[$methodName] = $method; |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
return $result; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public static function client($url, $options = null) { |
33
|
|
|
try { |
34
|
|
|
return new ar_connect_xmlrpcClient( ripcord::client($url, $options) ); |
35
|
|
|
} catch( Ripcord_Exception $e ) { |
36
|
|
|
return new ar_error($e->getMessage(), $e->getCode() ); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public static function server($methods, $options = null, $documentation = false) { |
41
|
|
|
try { |
42
|
|
|
return new ar_connect_xmlrpcServer( ripcord::server( |
43
|
|
|
self::services( $methods ), |
44
|
|
|
$options, |
45
|
|
|
$documentation ? new ar_connect_xmlrpcDocumentor( $options, $documentation ) : false |
46
|
|
|
) ); |
47
|
|
|
} catch( Ripcord_Exception $e ) { |
48
|
|
|
return new ar_error($e->getMessage(), $e->getCode() ); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function base64($binary) { |
53
|
|
|
return ripcord::base64( $binary ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function binary($base64) { |
57
|
|
|
try { |
58
|
|
|
return ripcord::binary( $base64 ); |
59
|
|
|
} catch( Ripcord_Exception $e ) { |
60
|
|
|
return new ar_error($e->getMessage(), $e->getCode() ); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public static function datetime($timestamp) { |
65
|
|
|
return ripcord::datetime($timestamp); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public static function timestamp($datetime) { |
69
|
|
|
try { |
70
|
|
|
return ripcord::timestamp($datetime); |
71
|
|
|
} catch( Ripcord_Exception $e ) { |
72
|
|
|
return new ar_error($e->getMessage(), $e->getCode() ); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function fault($code, $message) { |
77
|
|
|
return ripcord::fault($code, $message); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public static function isFault($fault) { |
81
|
|
|
return ripcord::isFault($fault); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public static function getType($arg) { |
85
|
|
|
return ripcord::getType($arg); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public static function encodeCall() { |
89
|
|
|
$params = func_get_args(); |
90
|
|
|
return call_user_func_array( array('ripcord', 'encodeCall'), $params ); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
class ar_connect_xmlrpcClient extends arBase { |
95
|
|
|
private $wrapped = null; |
96
|
|
|
|
97
|
|
|
public function __construct( $wrapped ) { |
98
|
|
|
$this->wrapped = $wrapped; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function __get($name) { |
102
|
|
|
$result = $this->wrapped->{$name}; |
103
|
|
|
if ( $result instanceof Ripcord_Client ) { |
104
|
|
|
try { |
105
|
|
|
return new ar_connect_xmlrpcClient($result); // FIXME: use clone here instead? |
106
|
|
|
} catch( Ripcord_Exception $e ) { |
107
|
|
|
return new ar_error($e->getMessage(), $e->getCode() ); |
108
|
|
|
} |
109
|
|
|
} else { |
110
|
|
|
return $result; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function __call($method, $params) { |
115
|
|
|
try { |
116
|
|
|
if ($method[0]=='_') { |
117
|
|
|
$method = substr($method, 1); |
118
|
|
|
} |
119
|
|
|
$result = $this->wrapped->__call($method, $params); |
120
|
|
|
if ( $result instanceof Ripcord_Client ) { |
121
|
|
|
return new ar_connect_xmlrpcClient($result); |
122
|
|
|
} else { |
123
|
|
|
return $result; |
124
|
|
|
} |
125
|
|
|
} catch( Ripcord_Exception $e ) { |
126
|
|
|
return new ar_error($e->getMessage(), $e->getCode() ); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function __set($name, $value) { |
131
|
|
|
$this->wrapped->{$name} = $value; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
class ar_connect_xmlrpcServer extends arBase { |
136
|
|
|
private $wrapped = null; |
137
|
|
|
|
138
|
|
|
public function __construct( $wrapped ) { |
139
|
|
|
$this->wrapped = $wrapped; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function __get($name) { |
143
|
|
|
$result = $this->wrapped->{$name}; |
144
|
|
|
return $result; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function __call($method, $params) { |
148
|
|
|
if ($method[0]=='_') { |
149
|
|
|
$method = substr($method, 1); |
150
|
|
|
} |
151
|
|
|
return call_user_func_array( array($this->wrapped, $method), $params); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function __set($name, $value) { |
155
|
|
|
$this->wrapped->{$name} = $value; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
class ar_connect_xmlrpcDocumentor extends arBase implements Ripcord_Documentor_Interface { |
160
|
|
|
private $documentation = null; |
161
|
|
|
|
162
|
|
|
public function __construct( $options = null ) { // FIXME: this is evil. Ripcord_Documentor_Interface no longer has __construct in it. |
|
|
|
|
163
|
|
|
$args = func_get_args(); |
164
|
|
|
if (isset($args[1])) { |
165
|
|
|
$this->documentation = $args[1]; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function getIntroSpectionXML() { |
170
|
|
|
return false; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function setMethodData($methods) { |
174
|
|
|
return false; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function handle($request) { |
178
|
|
|
echo $this->documentation; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.