4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Output;
14 use Symfony\Component\Console\Formatter\OutputFormatter;
15 use Symfony\Component\Console\Formatter\OutputFormatterInterface;
16 use Symfony\Component\Console\Output\ConsoleOutputInterface;
19 * ConsoleOutput is the default class for all CLI output. It uses STDOUT.
21 * This class is a convenient wrapper around `StreamOutput`.
23 * $output = new ConsoleOutput();
25 * This is equivalent to:
27 * $output = new StreamOutput(fopen('php://stdout', 'w'));
29 * @author Fabien Potencier <fabien@symfony.com>
33 class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
40 * @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL,
41 * self::VERBOSITY_VERBOSE)
42 * @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
43 * @param OutputFormatter $formatter Output formatter instance
47 public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
49 $outputStream = 'php://stdout';
50 if (!$this->hasStdoutSupport()) {
51 $outputStream = 'php://output';
54 parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
56 $this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $formatter);
59 public function setDecorated($decorated)
61 parent::setDecorated($decorated);
62 $this->stderr->setDecorated($decorated);
65 public function setFormatter(OutputFormatterInterface $formatter)
67 parent::setFormatter($formatter);
68 $this->stderr->setFormatter($formatter);
71 public function setVerbosity($level)
73 parent::setVerbosity($level);
74 $this->stderr->setVerbosity($level);
78 * @return OutputInterface
80 public function getErrorOutput()
85 public function setErrorOutput(OutputInterface $error)
87 $this->stderr = $error;
91 * Returns true if current environment supports writing console output to
94 * IBM iSeries (OS400) exhibits character-encoding issues when writing to
95 * STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
100 protected function hasStdoutSupport()
102 return ('OS400' != php_uname('s'));