2010-01-04 14:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-01-04 14:42:28 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-01-04 14:42:28 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-01-04 14:42:28 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Console\Output;
|
|
|
|
|
2011-12-16 14:08:35 +00:00
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
2011-03-17 15:53:46 +00:00
|
|
|
|
2010-01-04 14:42:28 +00:00
|
|
|
/**
|
|
|
|
* ConsoleOutput is the default class for all CLI output. It uses STDOUT.
|
|
|
|
*
|
|
|
|
* This class is a convenient wrapper around `StreamOutput`.
|
|
|
|
*
|
|
|
|
* $output = new ConsoleOutput();
|
|
|
|
*
|
|
|
|
* This is equivalent to:
|
|
|
|
*
|
|
|
|
* $output = new StreamOutput(fopen('php://stdout', 'w'));
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-03-24 08:39:53 +00:00
|
|
|
*
|
|
|
|
* @api
|
2010-01-04 14:42:28 +00:00
|
|
|
*/
|
2011-12-16 14:08:35 +00:00
|
|
|
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
|
2010-01-04 14:42:28 +00:00
|
|
|
{
|
2011-12-16 14:08:35 +00:00
|
|
|
private $stderr;
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
2013-05-14 17:38:03 +01:00
|
|
|
* @param integer $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
|
|
|
|
* @param Boolean|null $decorated Whether to decorate messages (null for auto-guessing)
|
|
|
|
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
|
2011-03-24 08:39:53 +00:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2011-12-17 21:48:01 +00:00
|
|
|
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2012-04-29 16:20:44 +01:00
|
|
|
$outputStream = 'php://stdout';
|
|
|
|
if (!$this->hasStdoutSupport()) {
|
|
|
|
$outputStream = 'php://output';
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
|
2012-05-11 17:14:47 +01:00
|
|
|
|
2011-12-16 14:08:35 +00:00
|
|
|
$this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $formatter);
|
|
|
|
}
|
|
|
|
|
2013-05-14 17:52:49 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-12-16 14:08:35 +00:00
|
|
|
public function setDecorated($decorated)
|
|
|
|
{
|
|
|
|
parent::setDecorated($decorated);
|
|
|
|
$this->stderr->setDecorated($decorated);
|
|
|
|
}
|
|
|
|
|
2013-05-14 17:52:49 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-12-16 14:08:35 +00:00
|
|
|
public function setFormatter(OutputFormatterInterface $formatter)
|
|
|
|
{
|
|
|
|
parent::setFormatter($formatter);
|
|
|
|
$this->stderr->setFormatter($formatter);
|
|
|
|
}
|
|
|
|
|
2013-05-14 17:52:49 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-12-16 14:08:35 +00:00
|
|
|
public function setVerbosity($level)
|
|
|
|
{
|
|
|
|
parent::setVerbosity($level);
|
|
|
|
$this->stderr->setVerbosity($level);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-14 17:52:49 +01:00
|
|
|
* {@inheritdoc}
|
2011-12-16 14:08:35 +00:00
|
|
|
*/
|
|
|
|
public function getErrorOutput()
|
|
|
|
{
|
|
|
|
return $this->stderr;
|
|
|
|
}
|
|
|
|
|
2013-05-14 17:52:49 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-12-16 14:08:35 +00:00
|
|
|
public function setErrorOutput(OutputInterface $error)
|
|
|
|
{
|
|
|
|
$this->stderr = $error;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2012-04-29 16:20:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if current environment supports writing console output to
|
|
|
|
* STDOUT.
|
|
|
|
*
|
|
|
|
* IBM iSeries (OS400) exhibits character-encoding issues when writing to
|
|
|
|
* STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
|
|
|
|
* output.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
protected function hasStdoutSupport()
|
|
|
|
{
|
|
|
|
return ('OS400' != php_uname('s'));
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-01-04 14:42:28 +00:00
|
|
|
}
|