Understanding the matter of ponctual debugging, you can always print debug messages with echo or var_dump
If you plan to use a command without Symfony's application with global debug messages, here's a way to do this.
Symfony offers 3 different OutputInterfaces
- NullOutput - Will result in no output at all and keep the command quiet
- ConsoleOutput - Will result in console messages
- StreamOutput - Will result in printing messages into a given stream
Debugging to a file
Doing such, whenever you call $output->writeln() in your command, it will write a new line in /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);
Debugging in the console
It is quietly the same process, except that you use 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);
No debugging
No message will be printed
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);
OutputInterface.OutputInterfacewere given, PHP would throw an error. Are you usingSymfony\Component\Console\Applicationto run them ? Or is it a custom caller ?Command. Actually I want to print some Debug message in my Fixtures github.com/doctrine/DoctrineFixturesBundle. I am only able to create the Fixtures Class and there is noOutputInterfaceavailable.echowhile debugging ? If you want to run the command and output console messages you can use$command = new MyCommand; $command->run(new ArrayInput($parameters), new ConsoleOutput());