3 回答

TA貢獻1886條經(jīng)驗 獲得超2個贊
您的中間件沒有實現(xiàn) PSR-15。您不應該傳遞響應,而是傳遞請求處理程序接口:
namespace Psr\Http\Server;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
/**
* Participant in processing a server request and response.
*
* An HTTP middleware component participates in processing an HTTP message:
* by acting on the request, generating the response, or forwarding the
* request to a subsequent middleware and possibly acting on its response.
*/
interface MiddlewareInterface
{
/**
* Process an incoming server request.
*
* Processes an incoming server request in order to produce a response.
* If unable to produce the response itself, it may delegate to the provided
* request handler to do so.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;
}
https://www.php-fig.org/psr/psr-15/

TA貢獻1810條經(jīng)驗 獲得超4個贊
首先,您需要檢查您使用的是哪個超薄版本,當我開始學習時,我也遇到了這個錯誤/問題,但您想解決這個問題,您可以在您的代碼中進行此編輯。
$APP = AppFactory::create();
$app->setBasePath("/myapp/public/index.php");
$APP->add(function(Request $request, Response $response, callable $next){
$response = $next($request,$response);
return $response;
});
- 3 回答
- 0 關注
- 147 瀏覽
添加回答
舉報