You are here

class StreamOutput in Zircon Profile 8

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

StreamOutput writes the output to a given stream.

Usage:

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

As `StreamOutput` can use any stream, you can also use a file:

$output = new StreamOutput(fopen('/path/to/output.log', 'a', false));

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of StreamOutput

11 files declare their use of StreamOutput
ApplicationTest.php in vendor/symfony/console/Tests/ApplicationTest.php
ApplicationTester.php in vendor/symfony/console/Tester/ApplicationTester.php
CommandTester.php in vendor/symfony/console/Tester/CommandTester.php
LegacyDialogHelperTest.php in vendor/symfony/console/Tests/Helper/LegacyDialogHelperTest.php
LegacyProgressHelperTest.php in vendor/symfony/console/Tests/Helper/LegacyProgressHelperTest.php

... See full list

File

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

Namespace

Symfony\Component\Console\Output
View source
class StreamOutput extends Output {
  private $stream;

  /**
   * Constructor.
   *
   * @param resource                      $stream    A stream resource
   * @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)
   *
   * @throws \InvalidArgumentException When first argument is not a real stream
   */
  public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null) {
    if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
      throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
    }
    $this->stream = $stream;
    if (null === $decorated) {
      $decorated = $this
        ->hasColorSupport();
    }
    parent::__construct($verbosity, $decorated, $formatter);
  }

  /**
   * Gets the stream attached to this StreamOutput instance.
   *
   * @return resource A stream resource
   */
  public function getStream() {
    return $this->stream;
  }

  /**
   * {@inheritdoc}
   */
  protected function doWrite($message, $newline) {
    if (false === @fwrite($this->stream, $message . ($newline ? PHP_EOL : ''))) {

      // should never happen
      throw new \RuntimeException('Unable to write output.');
    }
    fflush($this->stream);
  }

  /**
   * Returns true if the stream supports colorization.
   *
   * Colorization is disabled if not supported by the stream:
   *
   *  -  Windows without Ansicon, ConEmu or Mintty
   *  -  non tty consoles
   *
   * @return bool true if the stream supports colorization, false otherwise
   */
  protected function hasColorSupport() {
    if (DIRECTORY_SEPARATOR === '\\') {
      return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
    }
    return function_exists('posix_isatty') && @posix_isatty($this->stream);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::setDecorated public function Sets the decorated flag. Overrides OutputInterface::setDecorated 1
Output::setFormatter public function Sets output formatter. Overrides OutputInterface::setFormatter 1
Output::setVerbosity public function Sets the verbosity of the output. Overrides OutputInterface::setVerbosity 1
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.
StreamOutput::__construct public function Constructor. Overrides Output::__construct 1