ConsoleOutput.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\OutputFormatter;
  12. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  13. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  14. /**
  15. * ConsoleOutput is the default class for all CLI output. It uses STDOUT.
  16. *
  17. * This class is a convenient wrapper around `StreamOutput`.
  18. *
  19. * $output = new ConsoleOutput();
  20. *
  21. * This is equivalent to:
  22. *
  23. * $output = new StreamOutput(fopen('php://stdout', 'w'));
  24. *
  25. * @author Fabien Potencier <fabien@symfony.com>
  26. *
  27. * @api
  28. */
  29. class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
  30. {
  31. private $stderr;
  32. /**
  33. * Constructor.
  34. *
  35. * @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL,
  36. * self::VERBOSITY_VERBOSE)
  37. * @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
  38. * @param OutputFormatter $formatter Output formatter instance
  39. *
  40. * @api
  41. */
  42. public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
  43. {
  44. parent::__construct(fopen('php://stdout', 'w'), $verbosity, $decorated, $formatter);
  45. $this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $formatter);
  46. }
  47. public function setDecorated($decorated)
  48. {
  49. parent::setDecorated($decorated);
  50. $this->stderr->setDecorated($decorated);
  51. }
  52. public function setFormatter(OutputFormatterInterface $formatter)
  53. {
  54. parent::setFormatter($formatter);
  55. $this->stderr->setFormatter($formatter);
  56. }
  57. public function setVerbosity($level)
  58. {
  59. parent::setVerbosity($level);
  60. $this->stderr->setVerbosity($level);
  61. }
  62. /**
  63. * @return OutputInterface
  64. */
  65. public function getErrorOutput()
  66. {
  67. return $this->stderr;
  68. }
  69. public function setErrorOutput(OutputInterface $error)
  70. {
  71. $this->stderr = $error;
  72. }
  73. }