了解准时调试的问题后,您始终可以使用以下命令打印调试消息echo
or var_dump
如果您打算在没有 Symfony 应用程序的情况下使用带有全局调试消息的命令,可以使用以下方法。
Symfony 提供 3 种不同的OutputInterface
s
-
空输出 http://api.symfony.com/2.3/Symfony/Component/Console/Output/NullOutput.html- 将导致根本没有输出并保持命令安静
-
控制台输出 http://api.symfony.com/2.3/Symfony/Component/Console/Output/ConsoleOutput.html- 将导致控制台消息
-
流输出 http://api.symfony.com/2.3/Symfony/Component/Console/Output/StreamOutput.html- 将导致将消息打印到给定的流中
调试到文件
这样做,每当你打电话时$output->writeln()
在你的命令中,它将写入一个新行/path/to/debug/file.log
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Acme\FooBundle\Command\MyCommand;
$params = array();
$input = new ArrayInput($params);
$file = '/path/to/debug/file.log';
$handle = fopen($file, 'w+');
$output = new StreamOutput($handle);
$command = new MyCommand;
$command->run($input, $output);
fclose($handle);
在控制台中调试
这是相同的过程,只是您使用ConsoleOutput
instead
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Acme\FooBundle\Command\MyCommand;
$params = array();
$input = new ArrayInput($params);
$output = new ConsoleOutput();
$command = new MyCommand;
$command->run($input, $output);
无需调试
不会打印任何消息
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Acme\FooBundle\Command\MyCommand;
$params = array();
$input = new ArrayInput($params);
$output = new NullOutput();
$command = new MyCommand;
$command->run($input, $output);