ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
Client.php
Go to the documentation of this file.
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 
40 // }}}
41 
42 // dependencies {{{
43 require_once 'XML/RPC2/Exception.php';
44 require_once 'XML/RPC2/Backend.php';
45 // }}}
46 
72 abstract class XML_RPC2_Client
73 {
74  const VERSION = '1.0.4';
75  // {{{ properties
76 
82  protected $uri = null;
83 
89  protected $proxy = null;
90 
96  protected $prefix = null;
97 
103  protected $debug = false;
104 
110  protected $encoding = 'iso-8859-1';
111 
117  protected $sslverify = true;
118 
119  // }}}
120  // {{{ remoteCall___()
121 
127  protected $uglyStructHack = true;
128 
138  public abstract function remoteCall___($methodName, $parameters);
139 
140  // }}}
141  // {{{ constructor
142 
153  protected function __construct($uri, $options = array())
154  {
155  if (!$uriParse = parse_url($uri)) {
156  throw new XML_RPC2_InvalidUriException(sprintf('Client URI \'%s\' is not valid', $uri));
157  }
158  $this->uri = $uri;
159  if (isset($options['prefix'])) {
160  if (!($this->testMethodName___($options['prefix']))) {
161  throw new XML_RPC2_InvalidPrefixException(sprintf('Prefix \'%s\' is not valid', $options['prefix']));
162  }
163  $this->prefix = $options['prefix'];
164  }
165  if (isset($options['proxy'])) {
166  if (!$proxyParse = parse_url($options['proxy'])) {
167  throw new XML_RPC2_InvalidProxyException(sprintf('Proxy URI \'%s\' is not valid', $options['proxy']));
168  }
169  $this->proxy = $options['proxy'];
170  }
171  if (isset($options['debug'])) {
172  if (!(is_bool($options['debug']))) {
173  throw new XML_RPC2_InvalidDebugException(sprintf('Debug \'%s\' is not valid', $options['debug']));
174  }
175  $this->debug = $options['debug'];
176  }
177  if (isset($options['encoding'])) {
178  // TODO : control & exception
179  $this->encoding = $options['encoding'];
180  }
181  if (isset($options['uglyStructHack'])) {
182  $this->uglyStructHack = $options['uglyStructHack'];
183  }
184  if (isset($options['sslverify'])) {
185  if (!(is_bool($options['sslverify']))) {
186  throw new XML_RPC2_InvalidSslverifyException(sprintf('SSL verify \'%s\' is not valid', $options['sslverify']));
187  }
188  $this->sslverify = $options['sslverify'];
189  }
190  }
191 
192  // }}}
193  // {{{ create()
194 
205  public static function create($uri, $options = array())
206  {
207  if (isset($options['backend'])) {
208  XML_RPC2_Backend::setBackend($options['backend']);
209  }
211  return new $backend($uri, $options);
212  }
213 
214  // }}}
215  // {{{ __call()
216 
230  public function __call($methodName, $parameters)
231  {
232  $args = array($methodName, $parameters);
233  return @call_user_func_array(array($this, 'remoteCall___'), $args);
234  }
235 
236  // }}}
237  // {{{ displayDebugInformations___()
238 
248  protected function displayDebugInformations___($request, $body)
249  {
250  print '<pre>';
251  print "***** Request *****\n";
252  print htmlspecialchars($request);
253  print "***** End Of request *****\n\n";
254  print "***** Server response *****\n";
255  print htmlspecialchars($body);
256  print "\n***** End of server response *****\n\n";
257  }
258 
259  // }}}
260  // {{{ displayDebugInformations2___()
261 
271  {
272  print "***** Decoded result *****\n";
273  print_r($result);
274  print "\n***** End of decoded result *****";
275  print '</pre>';
276  }
277 
278  // }}}
279  // {{{ testMethodName___()
280 
290  protected function testMethodName___($methodName)
291  {
292  return (preg_match('~^[a-zA-Z0-9_.:/]*$~', $methodName));
293  }
294 
295 }
296 
297 ?>