Slim 4已经在这里了,我正在尝试迁移到Slim 4。一切都很好,但是当我尝试实现它时CSRF返回了一个错误。我尝试了最简单的设置,但是我得到了这个错误:
- 留言**:传递给Slim\Csrf\Guard::__invoke()的参数2必须是Psr\Http\Message\ResponseInterface的示例,给定的Slim\Routing\RouteRunner的示例,在第180行的/Volumes/Web/slim/vendor/slim/slim/Slim/MiddlewareDispatcher.php中调用
- 文件**:/卷/网站/slim/供应商/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();
任何帮助都非常感谢!谢谢!
2条答案
按热度按时间xu3bshqb1#
这个包与Slim4不兼容,我写了一个 Package 器,这样你就可以使用它了。
'
'
snvhrwxg2#
相关位为:
中间件回调的签名发生了变化,在Slim/3中曾经是这样的:
...然后该方法必须像
$next($request, $response)
一样调用$next
。在Slim/4中是这样的:
..,并且对
$handler
的内部调用是$handler->handle($request)
。该库似乎没有针对Slim/4进行更新。它在composer.json中声明Slim/3为dev(?)依赖项,并在README.md中提及。修复该库或在其上编写兼容的 Package 器可能并不困难,但如果您不熟悉整个生态系统,安装a replacement可能更容易。