2 <head><title>xmlrpc - Proxy demo</title></head>
5 <h2>Query server using a 'proxy' object</h2>
6 <h3>The code demonstrates usage for the terminally lazy. For a more complete proxy, look at at the Wrapper class</h3>
9 include_once __DIR__ . "/../../src/Autoloader.php";
10 PhpXmlRpc\Autoloader::register();
15 protected $prefix = 'examples.';
17 public function __construct(PhpXmlRpc\Client $client)
19 $this->client = $client;
23 * Translates any method call to an xmlrpc call.
27 * @param string $name remote function name. Will be prefixed
28 * @param array $arguments
34 function __call($name, $arguments)
36 $encoder = new PhpXmlRpc\Encoder();
37 $valueArray = array();
38 foreach ($arguments as $parameter) {
39 $valueArray[] = $encoder->encode($parameter);
42 // just in case this was set to something else
43 $this->client->return_type = 'phpvals';
45 $resp = $this->client->send(new PhpXmlRpc\Request($this->prefix.$name, $valueArray));
47 if ($resp->faultCode()) {
48 throw new Exception($resp->faultString(), $resp->faultCode());
50 return $resp->value();
56 $stateNo = rand(1, 51);
57 $proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client('http://phpxmlrpc.sourceforge.net/server.php'));
58 $stateName = $proxy->getStateName($stateNo);
60 echo "State $stateNo is ".htmlspecialchars($stateName);