我使用symfony 6.1和PHP8.1.我想知道是否有一种方法可以让symfony控制器不返回任何内容.原因是我用的是Botman,不幸的是它自己给客户发了一个回复...因此,我需要让我的控制器不返回任何内容.
/**
* @param Request $request
*
* @return Response
*/
#[Route('/botman', methods: 'POST')]
public function test(Request $request): Response
{
DriverManager::loadDriver(WebDriver::class);
$adapter = new FilesystemAdapter();
$botman = BotManFactory::create([], new SymfonyCache($adapter), $request);
$botman->hears('hello', static function (BotMan $bot) {
$bot->reply('Yoooooo'); //<- Send a response to the client
});
$botman->fallback(static function (BotMan $bot) {
$bot->reply('try again'); //<- Send a response to the client
});
$botman->listen(); // Launch the maching callback
return new Response(); //Crash because a response have already been sent
}
这就是我在浏览器判断器上得到的信息.
{
"status": 200,
"messages": [
{
"type": "text",
"text": "try again",
"attachment": null,
"additionalParameters": []
}
]
}{
"type": "https:\/\/tools.ietf.org\/html\/rfc2616#section-10",
"title": "An error occurred",
"status": 500,
"detail": "Warning: Cannot modify header information - headers already sent by (output started at C:\\Users\\cimba\\Documents\\botman\\vendor\\symfony\\http-foundation\\Response.php:1265)",
"class": "ErrorException",
"trace": [...]
}
我唯一的解决方案是exit();
或die();
,而不是return
,但我认为它不适合生产…也许有一种方法可以避免Botman发送它的响应,或者告诉symfony我希望我的控制器不返回任何东西(因为Botman没有symfony).