ConsoleOutput.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Output;
  11. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  12. /**
  13. * ConsoleOutput is the default class for all CLI output. It uses STDOUT.
  14. *
  15. * This class is a convenient wrapper around `StreamOutput`.
  16. *
  17. * $output = new ConsoleOutput();
  18. *
  19. * This is equivalent to:
  20. *
  21. * $output = new StreamOutput(fopen('php://stdout', 'w'));
  22. *
  23. * @author Fabien Potencier <fabien@symfony.com>
  24. *
  25. * @api
  26. */
  27. class ConsoleOutput extends StreamOutput
  28. {
  29. /**
  30. * Constructor.
  31. *
  32. * @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL,
  33. * self::VERBOSITY_VERBOSE)
  34. * @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
  35. * @param OutputFormatter $formatter Output formatter instance
  36. *
  37. * @api
  38. */
  39. public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
  40. {
  41. $outputStream = 'php://stdout';
  42. if (!$this->hasStdoutSupport()) {
  43. $outputStream = 'php://output';
  44. }
  45. parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
  46. }
  47. /**
  48. * Returns true if current environment supports writing console output to
  49. * STDOUT.
  50. *
  51. * IBM iSeries (OS400) exhibits character-encoding issues when writing to
  52. * STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
  53. * output.
  54. *
  55. * @return boolean
  56. */
  57. protected function hasStdoutSupport()
  58. {
  59. return ('OS400' != php_uname('s'));
  60. }
  61. }