Re: proposal for extending XML/RPC.php (part II)
| From: | Sebastien Person | Date: | Thu, 08 Apr 2004 08:24:37 +0000 |
| Subject: | Re: proposal for extending XML/RPC.php (part II) | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-27165@lists.php.net to get a copy of this message | ||
>
> You could find attached my patch. Let me know if there is any problem with
> my patch ...
>
As the list manager eat my attachment I copy it below (I also have reported a
bug as suggested) :
--- RPC.php Wed Oct 2 23:10:19 2002
+++ /usr/share/pear/XML/RPC.php Wed Apr 7 17:15:39 2004
@@ -393,8 +394,119 @@
$this->debug=0;
}
}
+
+ /**
+ * return associative array with all the available methods from the server
+ * and add the signature and doc string informations ('docstring')
+ *
+ * @access public
+ * @return array associative array of the discovered methods
+ */
+ function discover()
+ {
+ $methods = $this->listMethods();
+ $number_of_methods = sizeof($methods);
+
+ for ( $i= 0; $i < $number_of_methods; $i++){
+ $method = $methods[$i];
+ $return[$method]['docstring'] = $this->methodHelp($method);
+ $return[$method]['signature'] = $this->methodSignature($method);
+ }
+ return $return;
+ }
+
+
+ /**
+ * the purpose of this function is for helping developper to let them
+ * browse through a brwoser available method of the current XML-RPC
+ * server the client is attached to.
+ *
+ * @access public
+ * @return string HTML output representation of the available method
+ */
+ function discoverHTML(){
+
+ $discover = $this->discover();
+
+ foreach ($discover as $method_name => $method_array){
+ $output .= '<pre><b>' . $method_name . '</b>';
+
+ $number_of_params = sizeof($method_array['signature']);
+ for ($i = 0; $i < $number_of_params; $i++){
+ $output .= $i != 0 ? ', input:' : ' (output:';
+ $output .= $method_array['signature'][$i];
+ }
+ $output .= ')<br>'. $method_array['docstring'] .
'<br>';
+ $output .= '</pre>';
+ }
+ return $output;
+ }
+
+
+ /**
+ * list all available remote RPC methods
+ *
+ * @access public
+ * @return array an array of available method
+ */
+ function listMethods(){
+ $response = $this->send(new XML_RPC_Message('system.listMethods'));
+
+ if(!$response->faultcode()){
+ $method_value = $response->value();
+ return XML_RPC_Decode($method_value);
+ }
+ }
+
+ /**
+ * get doc string describing the method purpose
+ *
+ * @access public
+ * @param string method name
+ * @return string contains the description or an error message is something
went wrong
+ */
+ function methodHelp($method){
+ // request method doc
+ $doc_response = $this->send(new XML_RPC_Message("system.methodHelp",
+
array(XML_RPC_Encode($method))));
+ if ($doc_response == 0) {
+ return "Error occured : " . $this->errno() . $this->errstring();
+ }
+
+ if ($doc_response->faultcode()) {
+ return $doc_response->faultString();
+ }
+ return XML_RPC_Decode($doc_response->value());
+ }
+
+ /**
+ * return the signature for a given method
+ *
+ * @access public
+ * @param string method name
+ * @return array all availables signatures or a string describing the error
+ */
+ function methodSignature($method)
+ {
+ // request method signature
+ $sig_response = $this->send(new
XML_RPC_Message("system.methodSignature",
+ array(XML_RPC_Encode($method))));
+
+ // be sure there isn't any I/O trouble
+ if ($sig_response == 0) {
+ return "Error occured : " . $this->errno() . $this->errstring();
+ }
+ // signature stuff
+ if ($sig_response->faultcode()){
+ return $sig_response->faultString();
+ }
+ $sig_value = $sig_response->value();
+ $sig_array = XML_RPC_Decode($sig_response->value());
+ return $sig_array[0];
+ }
+
function setCredentials($u, $p)
{
$this->username=$u;
$this->password=$p;
@@ -514,9 +626,9 @@
function value() { return $this->xv; }
function serialize() {
$rs="<methodResponse>\n";
- if ($this->fn) {
+ if (isset($this->fn)) {
$rs.="<fault>
<value>
<struct>
<member>