2010-12-21 59 views
1

我有一個類的運行過程本身的Zend XMLRPC服務執行/電話

僞類

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 
} 

要執行類,我會做這樣的事情

include('MyClass.php'); 

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

現在我想通過XMLRPC調用來初始化它,我只是在方法調用中將它傳遞給變量。我正在關注這個tutorial,但我不確定我是否可以,這是我正在嘗試的。現在不是事先設定X,我只是去把它傳遞給startProcess功能

XML-RPC服務器:

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(); 

XML-RPC客戶端:

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); 

這是我得到的迴應:

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 
     ) 

) 

爲什麼不能正常工作?試圖找到一種讓XMLRPC啓動我的課程流程的方法,建議?

回答

2

好吧,經過多次調試我的代碼後,我發現我的docblock聲明不正確。

對於類中的每個公共函數,您需要有一個docblock來定義參數並返回數據類型。什麼我有

例子:它應該是什麼

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

例子:

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

希望這可以幫助別人