hprose / hprose-php

Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

看到有人问传额外参数(统一参数、公共参数、调试参数等)的问题

yjtec opened this issue · comments

commented

1、客户端传参的时候(设置options)使用这种方式
$options增加需要的参数,如
$options[]=['token'=>$token];
然后这样发起请求
$client->$action(...$options);
服务端的$action会接受到所有的$options参数,但其中新增的token会被传递给$action,当有默认值时会引起错误
2、服务端过滤掉自定义的参数
在服务端的onBeforeInvoke方法中去除掉自定义参数,注意其中的args需要使用引用(牛逼hprose作者传递的是引用)
$server->onBeforeInvoke = function ($name, &$args, $byref, \stdClass $context) use ($server) { unset($args[索引号]['token']) };
这样在hprose调用ivoke方法时就不存在这个参数了,调用你自己的方法也就没事了

hprose 3.0 中调用的参数通过参数直接传递,公共参数通过 $context->requestHeaders 传递。这样问题就简化了。

commented

hprose 3.0 中调用的参数通过参数直接传递,公共参数通过 $context->requestHeaders 传递。这样问题就简化了。

3.0在哪??composer里还是2.0啊

master 里面的是 3.0。