为了完成这个任务,我会创建自己的输出。
class MultipleOutput implements OutputInterface
{
protected $outputs = array();
public function __construct(array $outputs = array())
{
$this->setOutputs($outputs);
}
public function setOutputs(array $outputs = array())
{
foreach ($outputs as $output) {
$this->addOutput($outputs);
}
}
public function addOutput(OutputInterface $output)
{
$this->outputs[] = $output;
}
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
{
foreach ($this->outputs as $output) {
$output->write($messages, $newline, $type);
}
}
public function writeln($messages, $type = self::OUTPUT_NORMAL)
{
foreach ($this->outputs as $output) {
$output->writeln($messages, $type);
}
}
public function setVerbosity($level)
{
foreach ($this->outputs as $output) {
$output->setVerbosity($level);
}
}
/**
* Returns only the first one
*/
public function getVerbosity()
{
foreach ($this->outputs as $output) {
return $output->getVerbosity();
}
}
public function setDecorated($decorated)
{
foreach ($this->outputs as $output) {
$output->setDecorated($decorated);
}
}
/**
* Returns only the first one
*/
public function isDecorated()
{
foreach ($this->outputs as $output) {
return $output->isDecorated();
}
}
public function setFormatter(OutputFormatterInterface $formatter)
{
foreach ($this->outputs as $output) {
$output->setFormatter($formatter);
}
}
/**
* Returns only the first one
*/
public function getFormatter()
{
foreach ($this->outputs as $output) {
return $output->getFormatter();
}
}
}
然后你可以在你的应用程序中使用它
$application = new Application();
$application->add(new MyCommand1());
$application->add(new MyCommand2());
$output = new MultipleOutput(array(new StreamOutput, new ConsoleOutput));
$application->run(new ArgvInput, $output);