Slim 4 已经在这里,我正在尝试迁移到 Slim 4。一切都很好,但是当我尝试实现它时,CSRF 会返回一个错误。我尝试了最简单的设置,但出现此错误:
消息:传递给 Slim\Csrf\Guard::__invoke() 的参数 2 必须是 Psr\Http\Message\ResponseInterface 的实例,给定的 Slim\Routing\RouteRunner 实例,在 /Volumes/Web/slim/vendor/slim 中调用/slim/Slim/MiddlewareDispatcher.php 在第 180 行
文件:/Volumes/Web/slim/vendor/slim/csrf/src/Guard.php
这是我的代码:
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Csrf\Guard;
require __DIR__ . '/../vendor/autoload.php';
/**
* Instantiate App
*
* In order for the factory to work you need to ensure you have installed
* a supported PSR-7 implementation of your choice e.g.: Slim PSR-7 and a supported
* ServerRequest creator (included with Slim PSR-7)
*/
$app = AppFactory::create();
$app->add(Guard::class);
// Add Routing Middleware
$app->addRoutingMiddleware();
/*
* Add Error Handling Middleware
*
* @param bool $displayErrorDetails -> Should be set to false in production
* @param bool $logErrors -> Parameter is passed to the default ErrorHandler
* @param bool $logErrorDetails -> Display error details in error log
* which can be replaced by a callable of your choice.
* Note: This middleware should be added last. It will not handle any exceptions/errors
* for middleware added after it.
*/
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
// Define app routes
$app->get('/', function (Request $request, Response $response, $args) {
$response->getBody()->write('Hello');
return $response;
});
// Run app
$app->run();
任何帮助是极大的赞赏!谢谢!