关于supportRequest的一些疑问

dgkerry

问题描述

我尝试在中间件中使用support\Request(不用Webman\Http\Request的原因就是想在Request类中添加自定义的方法,但又不想改变vendor里面的文件),当我use support\Request后重启webman,却如下错误,请问为何呢?support\Request是继承Webman\Http\Request,如果我在中间件中用Webman\Http\Request替换掉support\Request却可以,有人能解答?

##错误代码
pid:1132815 Worker[1132815] process terminated with ERROR: E_COMPILE_ERROR "Declaration of
app\middleware\GolbalRequest::process(support\Request $request, callable $handler):
Webman\Http\Response must be compatible with Webman\MiddlewareInterface::process(Webman\Http\Request $request, callable $handler):
Webman\Http\Response in /www/wwwroot/testwebman.okbot.app/app/middleware/GolbalRequest.php
on line 9"

代码

<?php
namespace app\middleware;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;
use Workerman\Coroutine\Context;
use diyvendor\logger\Log;
class GolbalRequest implements MiddlewareInterface{
    public function process(Request $request, callable $handler) : Response
    {
        $response = $handler($request); // 继续向洋葱芯穿越,直至执行控制器得到响应
        return $response;
    }
}
?>
161 1 0
1个回答

th

自定义的方法独立出来

  • 暂无评论
×
🔝