PSR-15 process 方法为何移除 response 参数

moln
  • 72

我在把__invoke($request, $reaponse, callable $next) 升级PSR-15 接口实现时,发现个问题,比如升级前的代码:

class TestMiddleware {
  public function __invoke($request, $reaponse, callable $next)
{
    if (someInvalid($request)) {
        return $response->withStatus (403);
    }
    
    return $next($request, $response);
  }
}

升级后,没有 response 参数,我就得去依赖实现好的应用库

composer require zendframework/zend-diactoros 
class TestMiddleware implements MiddlewareInterface {
  public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
if (someInvalid($request)) {
        return (new Response ())->withStatus (403);
    }
    
    return $next($request, $response);
  }
}

这样多了个 psr/http-message 实现的依赖,感觉更麻烦了些。

评论
阅读 973
撰写回答

登录后参与交流、获取后续更新提醒

宣传栏