From abd17425a9d23d3716c4e24e49e66347ee329a88 Mon Sep 17 00:00:00 2001 From: John Kary Date: Sun, 21 Jun 2015 18:29:54 -0500 Subject: [PATCH 1/2] [Console] Fix error output on IBM iSeries OS400 --- .../Console/Output/ConsoleOutput.php | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Console/Output/ConsoleOutput.php b/src/Symfony/Component/Console/Output/ConsoleOutput.php index 3560f1c6fc5aa..4e522b2847879 100644 --- a/src/Symfony/Component/Console/Output/ConsoleOutput.php +++ b/src/Symfony/Component/Console/Output/ConsoleOutput.php @@ -43,14 +43,12 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface */ public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null) { - $outputStream = 'php://stdout'; - if (!$this->hasStdoutSupport()) { - $outputStream = 'php://output'; - } + $outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output'; + $errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output'; parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter); - $this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $this->getFormatter()); + $this->stderr = new StreamOutput(fopen($errorStream, 'w'), $verbosity, $decorated, $this->getFormatter()); } /** @@ -100,14 +98,32 @@ public function setErrorOutput(OutputInterface $error) * 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 bool */ protected function hasStdoutSupport() { - return ('OS400' != php_uname('s')); + return false === $this->isRunningOS400(); + } + + /** + * Returns true if current environment supports writing console output to + * STDERR. + * + * @return bool + */ + protected function hasStderrSupport() + { + return false === $this->isRunningOS400(); + } + + /** + * Checks if current executing environment is IBM iSeries (OS400), which + * doesn't properly convert character-encodings between ASCII to EBCDIC. + * + * @return bool + */ + private function isRunningOS400() + { + return 'OS400' === php_uname('s'); } } From ded4b92127650141d8d931e5c65a9c99ea771dbc Mon Sep 17 00:00:00 2001 From: John Kary Date: Sun, 21 Jun 2015 18:30:04 -0500 Subject: [PATCH 2/2] Add typehint --- src/Symfony/Component/Console/Output/ConsoleOutput.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Symfony/Component/Console/Output/ConsoleOutput.php b/src/Symfony/Component/Console/Output/ConsoleOutput.php index 4e522b2847879..708d171445bae 100644 --- a/src/Symfony/Component/Console/Output/ConsoleOutput.php +++ b/src/Symfony/Component/Console/Output/ConsoleOutput.php @@ -30,6 +30,9 @@ */ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface { + /** + * @var StreamOutput + */ private $stderr; /**