Pārlūkot izejas kodu

[Console] Selectively output to STDOUT or OUTPUT stream

Addresses issues with writing console output for IBM i5 Series (OS400).
The normal QP2TERM shell outputs garbage text when attempting to write
directly to STDOUT, likely because of EBCDIC character-encoding used
on IBM platforms. Writing to the OUTPUT mimics using 'echo' or 'print'
and prints properly in the console.

Fixes #1434
John Kary 13 gadi atpakaļ
vecāks
revīzija
5b92b9ed43
1 mainītis faili ar 21 papildinājumiem un 1 dzēšanām
  1. 21 1
      src/Symfony/Component/Console/Output/ConsoleOutput.php

+ 21 - 1
src/Symfony/Component/Console/Output/ConsoleOutput.php

@@ -42,6 +42,26 @@ class ConsoleOutput extends StreamOutput
      */
     public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
     {
-        parent::__construct(fopen('php://stdout', 'w'), $verbosity, $decorated, $formatter);
+        $outputStream = 'php://stdout';
+        if (!$this->hasStdoutSupport()) {
+            $outputStream = 'php://output';
+        }
+
+        parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
+    }
+
+    /**
+     * 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'));
     }
 }