30
30
*/
31
31
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
32
32
{
33
+ /**
34
+ * @var StreamOutput
35
+ */
33
36
private $ stderr ;
34
37
35
38
/**
@@ -43,14 +46,12 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
43
46
*/
44
47
public function __construct ($ verbosity = self ::VERBOSITY_NORMAL , $ decorated = null , OutputFormatterInterface $ formatter = null )
45
48
{
46
- $ outputStream = 'php://stdout ' ;
47
- if (!$ this ->hasStdoutSupport ()) {
48
- $ outputStream = 'php://output ' ;
49
- }
49
+ $ outputStream = $ this ->hasStdoutSupport () ? 'php://stdout ' : 'php://output ' ;
50
+ $ errorStream = $ this ->hasStderrSupport () ? 'php://stderr ' : 'php://output ' ;
50
51
51
52
parent ::__construct (fopen ($ outputStream , 'w ' ), $ verbosity , $ decorated , $ formatter );
52
53
53
- $ this ->stderr = new StreamOutput (fopen (' php://stderr ' , 'w ' ), $ verbosity , $ decorated , $ this ->getFormatter ());
54
+ $ this ->stderr = new StreamOutput (fopen ($ errorStream , 'w ' ), $ verbosity , $ decorated , $ this ->getFormatter ());
54
55
}
55
56
56
57
/**
@@ -100,14 +101,32 @@ public function setErrorOutput(OutputInterface $error)
100
101
* Returns true if current environment supports writing console output to
101
102
* STDOUT.
102
103
*
103
- * IBM iSeries (OS400) exhibits character-encoding issues when writing to
104
- * STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
105
- * output.
106
- *
107
104
* @return bool
108
105
*/
109
106
protected function hasStdoutSupport ()
110
107
{
111
- return ('OS400 ' != php_uname ('s ' ));
108
+ return false === $ this ->isRunningOS400 ();
109
+ }
110
+
111
+ /**
112
+ * Returns true if current environment supports writing console output to
113
+ * STDERR.
114
+ *
115
+ * @return bool
116
+ */
117
+ protected function hasStderrSupport ()
118
+ {
119
+ return false === $ this ->isRunningOS400 ();
120
+ }
121
+
122
+ /**
123
+ * Checks if current executing environment is IBM iSeries (OS400), which
124
+ * doesn't properly convert character-encodings between ASCII to EBCDIC.
125
+ *
126
+ * @return bool
127
+ */
128
+ private function isRunningOS400 ()
129
+ {
130
+ return 'OS400 ' === php_uname ('s ' );
112
131
}
113
132
}
0 commit comments