Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor demo files (client side): remove redundant ones; make sure a…
…ll use existing servers; add a proxy example
- Loading branch information
Showing
9 changed files
with
88 additions
and
348 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<html> | ||
<head><title>xmlrpc - Proxy demo</title></head> | ||
<body> | ||
<h1>proxy demo</h1> | ||
<h2>Query server using a 'proxy' object</h2> | ||
<h3>The code demonstrates usage for the terminally lazy</h3> | ||
<?php | ||
|
||
include_once __DIR__ . "/../../src/Autoloader.php"; | ||
PhpXmlRpc\Autoloader::register(); | ||
|
||
class PhpXmlRpcProxy | ||
{ | ||
protected $client; | ||
protected $prefix = 'examples.'; | ||
|
||
public function __construct(PhpXmlRpc\Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* @author Toth Istvan | ||
* | ||
* @param string $name remote function name. Will be prefixed | ||
* @param array $arguments | ||
* | ||
* @return mixed | ||
* | ||
* @throws Exception | ||
*/ | ||
function __call($name, $arguments) | ||
{ | ||
$encoder = new PhpXmlRpc\Encoder(); | ||
$valueArray = array(); | ||
foreach ($arguments as $parameter) { | ||
$valueArray[] = $encoder->encode($parameter); | ||
} | ||
|
||
// just in case this was set to something else | ||
$this->client->return_type = 'phpvals'; | ||
|
||
$resp = $this->client->send(new PhpXmlRpc\Request($this->prefix.$name, $valueArray)); | ||
|
||
if ($resp->faultCode()) { | ||
throw new Exception($resp->faultMessage(), $resp->faultCode); | ||
} else { | ||
return $resp->value(); | ||
} | ||
} | ||
|
||
} | ||
|
||
$stateNo = rand(1, 51); | ||
$proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client('http://phpxmlrpc.sourceforge.net/server.php')); | ||
$stateName = $proxy->getStateName($stateNo); | ||
|
||
echo "State $stateNo is ".htmlspecialchars($stateName); |
Oops, something went wrong.