我有一个像这样的 Symfony 5 命令:
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
....
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->input = $input;
$this->output = $output;
$this->io = new SymfonyStyle($input, $output);
....
}
此命令生成大量带有$this->io->caution(...)、$this->io->block(....)等 的输出$this->io->text(....)。
有时(不总是:有一些运行时条件),在执行结束时,我想访问命令生成的整个输出,然后通过电子邮件发送。那么....我怎样才能取回OutputInterface显示的所有内容?有$this->output->getBuffer()什么吗?
我可以毫无问题地交换OutputInterface $output其他东西(logger,也许?),只要我仍然可以像我现在所做的那样在 stdoutput (我的终端)上显示所有内容。
弑天下