Closed daviscai closed 5 years ago
@daviscai 可以直接提交一个PR到 swoft-component
其实我不是很赞成这么来改。。
@daviscai 你是打算直接使用Request代替easywechat里的Request直接注入到easywechat里么?如果是这样,你其实只是想解决request初始化的问题。
所以你可以主动初始化一下即可。
如下
$get = $request->getSwooleRequest()->get ?? [];
$post = $request->getSwooleRequest()->post ?? [];
$attr = [];
$cookies = $request->getSwooleRequest()->cookie ?? [];
$files = $request->getSwooleRequest()->files ?? [];
$server = $request->getSwooleRequest()->server ?? [];
$raw = $request->getSwooleRequest()->rawContent();
// 初始化 Request
$app->request->initialize($get, $post, $attr, $cookies, $files, $server, $raw);
@limingxinleo 你的方法可以解决问题,不过 easywechat的Request是通用的 Symfony\Component\HttpFoundation\Request 对象 , 而swoft Request 没有继承它的常用方法,其他工具类或者框架在swoft下可能会有问题,需要做适配,我觉得swoft Request 应该支持 Symfony Request 大部分常用方法,对开发者会更友好和降低学习成本
@daviscai 其实,这种情况可以基于Swoft Request再进行封装实现 Symfony Request的常用方法。
如果现在是Symfony Request,后面又有一个Symfony2 Request,Swoft Request肯定不能满足所有的效果。不过如果Psr里有RequestInterface的规范,Swoft肯定会去实现的。。
这里还希望你能谅解
get()
方法作为一个 query()
方法的别名这个我觉得可以有,但是 getContent()
别名 raw()
我是觉得有点奇怪的
建议升级到2.0, 2.0 已经正式发布
使用swoft开发微信公众号过程中发现swoft不支持easywechat使用的方法,下面代码亲测OK,希望官方支持下
/swoft/vendor/swoft/http-message/src/Server/Request.php
添加如下2个方法即可支持