1: <?php
2:
3: /*
4: * This file is part of the Symfony package.
5: *
6: * (c) Fabien Potencier <fabien@symfony.com>
7: *
8: * For the full copyright and license information, please view the LICENSE
9: * file that was distributed with this source code.
10: */
11:
12: namespace Symfony\Component\Console\Output;
13:
14: use Symfony\Component\Console\Formatter\OutputFormatterInterface;
15: use Symfony\Component\Console\Output\ConsoleOutputInterface;
16:
17: /**
18: * ConsoleOutput is the default class for all CLI output. It uses STDOUT.
19: *
20: * This class is a convenient wrapper around `StreamOutput`.
21: *
22: * $output = new ConsoleOutput();
23: *
24: * This is equivalent to:
25: *
26: * $output = new StreamOutput(fopen('php://stdout', 'w'));
27: *
28: * @author Fabien Potencier <fabien@symfony.com>
29: *
30: * @api
31: */
32: class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
33: {
34: private $stderr;
35:
36: /**
37: * Constructor.
38: *
39: * @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL,
40: * self::VERBOSITY_VERBOSE)
41: * @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
42: * @param OutputFormatterInterface $formatter Output formatter instance
43: *
44: * @api
45: */
46: public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
47: {
48: $outputStream = 'php://stdout';
49: if (!$this->hasStdoutSupport()) {
50: $outputStream = 'php://output';
51: }
52:
53: parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
54:
55: $this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $formatter);
56: }
57:
58: public function setDecorated($decorated)
59: {
60: parent::setDecorated($decorated);
61: $this->stderr->setDecorated($decorated);
62: }
63:
64: public function setFormatter(OutputFormatterInterface $formatter)
65: {
66: parent::setFormatter($formatter);
67: $this->stderr->setFormatter($formatter);
68: }
69:
70: public function setVerbosity($level)
71: {
72: parent::setVerbosity($level);
73: $this->stderr->setVerbosity($level);
74: }
75:
76: /**
77: * @return OutputInterface
78: */
79: public function getErrorOutput()
80: {
81: return $this->stderr;
82: }
83:
84: public function setErrorOutput(OutputInterface $error)
85: {
86: $this->stderr = $error;
87: }
88:
89: /**
90: * Returns true if current environment supports writing console output to
91: * STDOUT.
92: *
93: * IBM iSeries (OS400) exhibits character-encoding issues when writing to
94: * STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
95: * output.
96: *
97: * @return boolean
98: */
99: protected function hasStdoutSupport()
100: {
101: return ('OS400' != php_uname('s'));
102: }
103: }
104: