You are here

class ConsoleOutput in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Output/ConsoleOutput.php \Symfony\Component\Console\Output\ConsoleOutput

ConsoleOutput is the default class for all CLI output. It uses STDOUT.

This class is a convenient wrapper around `StreamOutput`.

$output = new ConsoleOutput();

This is equivalent to:

$output = new StreamOutput(fopen('php://stdout', 'w'));

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of ConsoleOutput

4 files declare their use of ConsoleOutput
Application.php in vendor/symfony/console/Application.php
ConsoleOutputTest.php in vendor/symfony/console/Tests/Output/ConsoleOutputTest.php
DebugHandlersListenerTest.php in vendor/symfony/http-kernel/Tests/EventListener/DebugHandlersListenerTest.php
Shell.php in vendor/symfony/console/Shell.php

File

vendor/symfony/console/Output/ConsoleOutput.php, line 29

Namespace

Symfony\Component\Console\Output
View source
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface {

  /**
   * @var StreamOutput
   */
  private $stderr;

  /**
   * Constructor.
   *
   * @param int                           $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
   * @param bool|null                     $decorated Whether to decorate messages (null for auto-guessing)
   * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
   */
  public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null) {
    parent::__construct($this
      ->openOutputStream(), $verbosity, $decorated, $formatter);
    $actualDecorated = $this
      ->isDecorated();
    $this->stderr = new StreamOutput($this
      ->openErrorStream(), $verbosity, $decorated, $this
      ->getFormatter());
    if (null === $decorated) {
      $this
        ->setDecorated($actualDecorated && $this->stderr
        ->isDecorated());
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setDecorated($decorated) {
    parent::setDecorated($decorated);
    $this->stderr
      ->setDecorated($decorated);
  }

  /**
   * {@inheritdoc}
   */
  public function setFormatter(OutputFormatterInterface $formatter) {
    parent::setFormatter($formatter);
    $this->stderr
      ->setFormatter($formatter);
  }

  /**
   * {@inheritdoc}
   */
  public function setVerbosity($level) {
    parent::setVerbosity($level);
    $this->stderr
      ->setVerbosity($level);
  }

  /**
   * {@inheritdoc}
   */
  public function getErrorOutput() {
    return $this->stderr;
  }

  /**
   * {@inheritdoc}
   */
  public function setErrorOutput(OutputInterface $error) {
    $this->stderr = $error;
  }

  /**
   * Returns true if current environment supports writing console output to
   * STDOUT.
   *
   * @return bool
   */
  protected function hasStdoutSupport() {
    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() {
    $checks = array(
      function_exists('php_uname') ? php_uname('s') : '',
      getenv('OSTYPE'),
      PHP_OS,
    );
    return false !== stristr(implode(';', $checks), 'OS400');
  }

  /**
   * @return resource
   */
  private function openOutputStream() {
    $outputStream = $this
      ->hasStdoutSupport() ? 'php://stdout' : 'php://output';
    return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
  }

  /**
   * @return resource
   */
  private function openErrorStream() {
    $errorStream = $this
      ->hasStderrSupport() ? 'php://stderr' : 'php://output';
    return fopen($errorStream, 'w');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConsoleOutput::$stderr private property
ConsoleOutput::getErrorOutput public function Gets the OutputInterface for errors. Overrides ConsoleOutputInterface::getErrorOutput
ConsoleOutput::hasStderrSupport protected function Returns true if current environment supports writing console output to STDERR.
ConsoleOutput::hasStdoutSupport protected function Returns true if current environment supports writing console output to STDOUT.
ConsoleOutput::isRunningOS400 private function Checks if current executing environment is IBM iSeries (OS400), which doesn't properly convert character-encodings between ASCII to EBCDIC.
ConsoleOutput::openErrorStream private function
ConsoleOutput::openOutputStream private function
ConsoleOutput::setDecorated public function Sets the decorated flag. Overrides Output::setDecorated
ConsoleOutput::setErrorOutput public function Sets the OutputInterface used for errors. Overrides ConsoleOutputInterface::setErrorOutput
ConsoleOutput::setFormatter public function Sets output formatter. Overrides Output::setFormatter
ConsoleOutput::setVerbosity public function Sets the verbosity of the output. Overrides Output::setVerbosity
ConsoleOutput::__construct public function Constructor. Overrides StreamOutput::__construct
Output::$formatter private property
Output::$verbosity private property
Output::getFormatter public function Returns current output formatter instance. Overrides OutputInterface::getFormatter
Output::getVerbosity public function Gets the current verbosity of the output. Overrides OutputInterface::getVerbosity
Output::isDebug public function
Output::isDecorated public function Gets the decorated flag. Overrides OutputInterface::isDecorated
Output::isQuiet public function
Output::isVerbose public function
Output::isVeryVerbose public function
Output::write public function Writes a message to the output. Overrides OutputInterface::write
Output::writeln public function Writes a message to the output and adds a newline at the end. Overrides OutputInterface::writeln
OutputInterface::OUTPUT_NORMAL constant
OutputInterface::OUTPUT_PLAIN constant
OutputInterface::OUTPUT_RAW constant
OutputInterface::VERBOSITY_DEBUG constant
OutputInterface::VERBOSITY_NORMAL constant
OutputInterface::VERBOSITY_QUIET constant
OutputInterface::VERBOSITY_VERBOSE constant
OutputInterface::VERBOSITY_VERY_VERBOSE constant
StreamOutput::$stream private property
StreamOutput::doWrite protected function Writes a message to the output. Overrides Output::doWrite
StreamOutput::getStream public function Gets the stream attached to this StreamOutput instance.
StreamOutput::hasColorSupport protected function Returns true if the stream supports colorization.