多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[Xunsearch PHP-SDK](http://www.xunsearch.com) v1.4.8 API 参考文档 # XSCommand [All Packages](#)| [属性](#)| [方法(函数)](#) | 包 | [XS](#) | |-----|-----| | 继承关系 | class XSCommand »[XSComponent](#) | | 版本 | 1.0.0 | | 源代码 | [sdk/php/lib/XSServer.class.php](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php) | XSCommand 命令对象是与服务端交互的最基本单位, 命令对象可自动转换为通讯字符串,命令结构参见 C 代码中的 struct xs_cmd 定义, 头部长度为 8字节. ### Public 属性 [隐去继承来的属性](#) | 名称 | 类型 | 描述 | 定义于 | |-----|-----|-----|-----| | [arg](#) | int | 获取属性 arg 的值 | XSCommand | | [arg1](#) | int | 参数1取值范围 0~255, 具体含义根据不同的 CMD 而变化 | XSCommand | | [arg2](#) | int | 参数2取值范围 0~255, 常用于存储 value no, 具体参照不同 CMD 而确定 | XSCommand | | [buf](#) | string | 主数据内容, 最长 2GB | XSCommand | | [buf1](#) | string | 辅数据内容, 最长 255字节 | XSCommand | | [cmd](#) | int | 命令代码通常是预定义常量 CMD_xxx, 取值范围 0~255 | XSCommand | ### Public 方法 [隐去继承来的方法](#) | 名称 | 描述 | 定义于 | |-----|-----|-----| | [__construct()](#) | 构造函数 | XSCommand | | [__get()](#) | 魔术方法 __get | [XSComponent](#) | | [__isset()](#) | 魔术方法 __isset | [XSComponent](#) | | [__set()](#) | 魔术方法 __set | [XSComponent](#) | | [__toString()](#) | 转换为封包字符串 | XSCommand | | [__unset()](#) | 魔术方法 __unset | [XSComponent](#) | | [getArg()](#) | 获取属性 arg 的值 | XSCommand | | [setArg()](#) | 设置属性 arg 的值 | XSCommand | ### 属性明细 arg属性 public int [**getArg**](#)() public void [**setArg**](#)(int $arg) 获取属性 arg 的值 arg1属性 public int **$arg1**; 参数1取值范围 0~255, 具体含义根据不同的 CMD 而变化 arg2属性 public int **$arg2**; 参数2取值范围 0~255, 常用于存储 value no, 具体参照不同 CMD 而确定 buf属性 public string **$buf**; 主数据内容, 最长 2GB buf1属性 public string **$buf1**; 辅数据内容, 最长 255字节 cmd属性 public int **$cmd**; 命令代码通常是预定义常量 CMD_xxx, 取值范围 0~255 ### 方法明细 __construct()方法 <table class="summaryTable"><tr><td colspan="3"><div class="signature2">public void <b>__construct</b>(mixed $cmd, int $arg1=0, int $arg2=0, string $buf='', string $buf1='')</div></td></tr><tr><td class="paramNameCol">$cmd</td> <td class="paramTypeCol">mixed</td> <td class="paramDescCol">命令类型或命令数组 当类型为 int 表示命令代码, 范围是 1~255, 参见 xs_cmd.inc.php 里的定义 当类型为 array 时忽略其它参数, 可包含 cmd, arg1, arg2, buf, buf1 这些键值</td></tr><tr><td class="paramNameCol">$arg1</td> <td class="paramTypeCol">int</td> <td class="paramDescCol">参数1, 其值为 0~255, 具体含义视不同 CMD 而确定</td></tr><tr><td class="paramNameCol">$arg2</td> <td class="paramTypeCol">int</td> <td class="paramDescCol">参数2, 其值为 0~255, 具体含义视不同 CMD 而确定, 常用于存储 value no</td></tr><tr><td class="paramNameCol">$buf</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">字符串内容, 最大长度为 2GB</td></tr><tr><td class="paramNameCol">$buf1</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">字符串内容1, 最大长度为 255字节</td></tr></table> **源码:**[sdk/php/lib/XSServer.class.php#L62](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php#L62) (**[显示](#)**) `public function __construct($cmd, $arg1 = 0, $arg2 = 0, $buf = '', $buf1 = '') {     if (is_array($cmd)) {         foreach ($cmd as $key => $value) {             if ($key === 'arg' || property_exists($this, $key)) {                 $this->$key = $value;             }         }     } else {         $this->cmd = $cmd;         $this->arg1 = $arg1;         $this->arg2 = $arg2;         $this->buf = $buf;         $this->buf1 = $buf1;     } }` 构造函数 __toString()方法 <table class="summaryTable"><tr><td colspan="3"><div class="signature2">public string <b>__toString</b>()</div></td></tr><tr><td class="paramNameCol">{return}</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">用于服务端交互的字符串</td></tr></table> **源码:**[sdk/php/lib/XSServer.class.php#L83](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php#L83) (**[显示](#)**) `public function __toString() {     if (strlen($this->buf1) > 0xff) {         $this->buf1 = substr($this->buf1, 0, 0xff);     }     return pack('CCCCI', $this->cmd, $this->arg1, $this->arg2, strlen($this->buf1), strlen($this->buf)) . $this->buf . $this->buf1; }` 转换为封包字符串 getArg()方法 <table class="summaryTable"><tr><td colspan="3"><div class="signature2">public int <b>getArg</b>()</div></td></tr><tr><td class="paramNameCol">{return}</td> <td class="paramTypeCol">int</td> <td class="paramDescCol">参数值</td></tr></table> **源码:**[sdk/php/lib/XSServer.class.php#L95](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php#L95) (**[显示](#)**) `public function getArg() {     return $this->arg2 | ($this->arg1 << 8); }` 获取属性 arg 的值 setArg()方法 <table class="summaryTable"><tr><td colspan="3"><div class="signature2">public void <b>setArg</b>(int $arg)</div></td></tr><tr><td class="paramNameCol">$arg</td> <td class="paramTypeCol">int</td> <td class="paramDescCol">参数值</td></tr></table> **源码:**[sdk/php/lib/XSServer.class.php#L104](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php#L104) (**[显示](#)**) `public function setArg($arg) {     $this->arg1 = ($arg >> 8) & 0xff;     $this->arg2 = $arg & 0xff; }` 设置属性 arg 的值 Copyright © 2008-2011 by [杭州云圣网络科技有限公司](http://www.xunsearch.com) All Rights Reserved.