2010-12-21 5 views
1

Ich habe eine Klasse, die läuft ein Prozess von selbstZend XMLRPC Dienst ausführen/Anruf Klasse

Pseudo-Klasse

class MyClass { 
    private $x; 
    private $y 

    // filename is INI file, each project have its own INI file 
    public function __construct($filename) { 
    // read and set value from INI file 
    // set some default values here as well 
    } 

    /** 
    * Start Process 
    * 
    * @param 
    * @return 
    */ 
    public function startProcess() { 
    // run process here 
    $y = $this->getX(); // and so on 
    echo "Process Started: ".$y."\n"; 
    } 
    // This is the change for the XMLRPC 
    /* 
    public function startProcess($value) { 
    // run process here 
    echo "Process Started: ".$value."\n"; 
    } 
    */ 

    /** 
    * Set X 
    * 
    * @param $x 
    * @return 
    */ 
    private function setX($x) { 
    $this->x = $x; 
    } 

    /** 
    * Get X 
    * 
    * @param 
    * @return $x 
    */ 
    private function getX() { 
    return $this->x; 
    } 

    // and so on 
} 

Um die Klasse ausführen ich etwas tun würde so

include('MyClass.php'); 

$process = new MyClass('file.ini'); 
$process->setX('blah'); 
$process->startProcess(); 

Nun möchte ich das durch einen XMLRPC-Aufruf initialisiert werden, wo ich einfach eine Variable im Methodenaufruf übergeben würde. Ich folgte diesem tutorial, aber ich bin nicht sicher, ob ich kann, hier ist, was ich versuche. Anstatt nun X der Einstellung vor der Hand werde ich nur an die Funktion startProcess passieren

XMLRPC Server:

ini_set("include_path", "/usr/share/php/libzend-framework-php"); 
require_once('Zend/XmlRpc/Server.php'); 

/** 
* Start Process Wrapper 
* 
* @param 
* @return 
*/ 
function startProcessWrapper($value) { 
    include('MyClass.php'); // I have change the startProcess() to take a variable 

    $process = new MyClass('file.ini'); 
    $process->startProcess('passing x here'); 
} 

$server = new Zend_XmlRpc_Server(); 
$server->addFunction('startProcessWrapper', 'webservice'); 
echo $server->handle(); 

XMLRPC Auftraggeber:

ini_set("include_path", "/usr/share/php/libzend-framework-php"); 
require_once('Zend/XmlRpc/Client.php'); 

$server = new Zend_XmlRpc_Client('http://localhost/xmlrpc_server.php'); 
$client = $server->getProxy(); 

$request = array(
    array(
    'methodName' => 'system.listMethods', 
    'params'  => array() 
), 
    array( 
    'methodName' => 'system.methodHelp', 
    'params'  => array('webservice.startProcess') 
), 
    array( 
    'methodName' => 'webservice.startProcess', 
    'params'  => array('123456') 
)); 

    $response = $client->system->multicall($request); 
    echo print_r($response,true); 

Hier ist die Antwort, die ich erhalten:

Array 
(
    [0] => Array 
     (
      [0] => system.listMethods 
      [1] => system.methodHelp 
      [2] => system.methodSignature 
      [3] => system.multicall 
      [4] => webservice.startProcess 
     ) 

    [1] => Start Process Wrapper 
    [2] => Array 
     (
      [faultCode] => 623 
      [faultString] => Calling parameters do not match signature 
     ) 

) 

Warum funktioniert das nicht? Ich versuche nur einen Weg zu finden, wie XMLRPC meinen Unterrichtsprozess anstoßen kann, Vorschläge?

Antwort

2

Ok, nach viel Debugging meines Codes fand ich, dass meine Docblock Deklaration falsch war.

Für jede öffentliche Funktion in der Klasse benötigen Sie einen Docblock, der die Parameter definiert und Datentypen zurückgibt.

Beispiel von dem, was ich hatte:

/** 
    * Set X 
    * 
    * @param $x 
    * @return 
    */ 
    public function setX($x) { 
    $this->x = $x; 
    } 

Beispiel von dem, was es sein sollte:

/** 
    * Set X, you can give more description here for help functionality 
    * 
    * @param string 
    * @return 
    */ 
    public function setX($x) { 
    $this->x = $x; 
    } 

Hoffnung hilft dies jemand