IXR_ClientMulticall
云策文档标注
概述
IXR_ClientMulticall 是 WordPress 中用于 XML-RPC 多调用操作的类,继承自 IXR_Client,支持批量执行远程过程调用。
关键要点
- 继承自 IXR_Client,用于处理 XML-RPC 多调用请求。
- 提供 addCall 方法添加调用,query 方法执行批量查询。
- 支持 PHP4 和 PHP5 构造函数,确保向后兼容性。
- 自 WordPress 1.5.0 引入,5.5.0 版本正式化参数签名。
代码示例
class IXR_ClientMulticall extends IXR_Client
{
var $calls = array();
function __construct( $server, $path = false, $port = 80 )
{
parent::IXR_Client($server, $path, $port);
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
}
function addCall( ...$args )
{
$methodName = array_shift($args);
$struct = array(
'methodName' => $methodName,
'params' => $args
);
$this->calls[] = $struct;
}
function query( ...$args )
{
return parent::query('system.multicall', $this->calls);
}
}注意事项
- 使用 addCall 方法时,第一个参数为方法名,后续参数为调用参数。
- query 方法内部调用父类的 query 方法,传递 system.multicall 和累积的调用数组。
- PHP4 构造函数 IXR_ClientMulticall 通过调用 self::__construct 实现兼容。
原文内容
Methods
| Name | Description |
|---|---|
| IXR_ClientMulticall::__construct | PHP5 constructor. |
| IXR_ClientMulticall::addCall | – |
| IXR_ClientMulticall::IXR_ClientMulticall | PHP4 constructor. |
| IXR_ClientMulticall::query | – |
Source
class IXR_ClientMulticall extends IXR_Client
{
var $calls = array();
/**
* PHP5 constructor.
*/
function __construct( $server, $path = false, $port = 80 )
{
parent::IXR_Client($server, $path, $port);
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
}
/**
* PHP4 constructor.
*/
public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) {
self::__construct( $server, $path, $port );
}
/**
* @since 1.5.0
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
* to the function signature.
*/
function addCall( ...$args )
{
$methodName = array_shift($args);
$struct = array(
'methodName' => $methodName,
'params' => $args
);
$this->calls[] = $struct;
}
/**
* @since 1.5.0
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
* to the function signature.
*
* @return bool
*/
function query( ...$args )
{
// Prepare multicall, then call the parent::query() method
return parent::query('system.multicall', $this->calls);
}
}
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |