Symfony provides other classes that implement OutputInterface. How can I provide instances of these classes - ideally from the command line or other config options - to a command?
My current workaround for using different Output objects is to immediately reassign $output to the preferred object like so:
<?php
namespace AppBundle\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\NullOutput;
class DebugCommand extends Command
{
protected function Configure()
{
$this->setName('AppBundle:DebugCommand');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output = new NullOutput();
$output->writeln('Done!');
}
}
But this feels sloppy. It would make much more sense to simply provide the intended object as a parameter to DebugCommand::execute(). Plus, If I decided I did want the output - I would have to modify the code to get the intended behavior.
How can I achieve this properly?
EDIT:
My hope is that it will be possible to set a default for each command. This would be helpful because I could create a new class that implements OutputInterface that would post output to, say, my team's Slack channel. But a different command might need to post to a different team's Slack channel. Being able to customize the output object for each command would be helpful as each command might affect different teams.