Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yjtec opened this issue Mar 13, 2020 · 3 comments

Comments

@yjtec
Copy link

yjtec commented Mar 13, 2020

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方法时就不存在这个参数了,调用你自己的方法也就没事了

@yjtec yjtec changed the title 看到有人问传额外参数的问题 看到有人问传额外参数(统一参数、公共参数、调试参数等)的问题 Mar 13, 2020
@andot
Copy link
Member

andot commented Mar 13, 2020

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

@yjtec
Copy link
Author

yjtec commented Mar 16, 2020

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

3.0在哪??composer里还是2.0啊

@andot
Copy link
Member

andot commented Mar 16, 2020

master 里面的是 3.0。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants