public function __call($method, $args = array()) { $params = array(); foreach ($args as $arg) { // argument already encoded, perhaps via encodeBinary if ($arg instanceof PhpXmlRpc\Value) { $params[] = $arg; continue; } // serialize all objects first if (is_object($arg)) { $arg = serialize($arg); } $params[] = $this->encoder->encode($arg); } $req = new PhpXmlRpc\Request($method, $params); $result = $this->client->send($req); if ($result === 0) { throw new Eventum_RPC_Exception($this->client->errstr); } if (is_object($result) && $result->faultCode()) { throw new Eventum_RPC_Exception($result->faultString()); } $value = $this->encoder->decode($result->value()); return $value; }
function getComments($req) { $err = ""; $ra = array(); $encoder = new PhpXmlRpc\Encoder(); $msgID = $encoder->decode($req->getParam(0)); $dbh = dba_open("/tmp/comments.db", "r", "db2"); if ($dbh) { $countID = "{$msgID}_count"; if (dba_exists($countID, $dbh)) { $count = dba_fetch($countID, $dbh); for ($i = 0; $i < $count; $i++) { $name = dba_fetch("{$msgID}_name_{$i}", $dbh); $comment = dba_fetch("{$msgID}_comment_{$i}", $dbh); // push a new struct onto the return array $ra[] = array("name" => $name, "comment" => $comment); } } } // if we generated an error, create an error return response if ($err) { return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err); } else { // otherwise, we create the right response return new PhpXmlRpc\Response($encoder->encode($ra)); } }
/** * Translates any method call to an xmlrpc call. * * @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->faultString(), $resp->faultCode()); } else { return $resp->value(); } }
<html> <head><title>xmlrpc - Getstatename demo</title></head> <body> <h1>Getstatename demo</h1> <h2>Send a U.S. state number to the server and get back the state name</h2> <h3>The code demonstrates usage of automatic encoding/decoding of php variables into xmlrpc values</h3> <?php include_once __DIR__ . "/../../src/Autoloader.php"; PhpXmlRpc\Autoloader::register(); if (isset($_POST["stateno"]) && $_POST["stateno"] != "") { $stateNo = (int) $_POST["stateno"]; $encoder = new PhpXmlRpc\Encoder(); $req = new PhpXmlRpc\Request('examples.getStateName', array($encoder->encode($stateNo))); print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n"; $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php"); $client->setDebug(1); $r = $client->send($req); if (!$r->faultCode()) { $v = $r->value(); print "<br/>State number <b>" . $stateNo . "</b> is <b>" . htmlspecialchars($encoder->decode($v)) . "</b><br/>"; } else { print "An error occurred: "; print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>"; } } else { $stateNo = ""; } print "<form action=\"getstatename.php\" method=\"POST\">\n<input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>\n<p>Enter a state number to query its name</p>"; ?>
function i_whichToolkit($req) { global $SERVER_SOFTWARE; $ret = array("toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/", "toolkitName" => PhpXmlRpc\PhpXmlRpc::$xmlrpcName, "toolkitVersion" => PhpXmlRpc\PhpXmlRpc::$xmlrpcVersion, "toolkitOperatingSystem" => isset($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE']); $encoder = new PhpXmlRpc\Encoder(); return new PhpXmlRpc\Response($encoder->encode($ret)); }