class StreamOutput in Zircon Profile 8
Same name and namespace in other branches
- 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
- class \Symfony\Component\Console\Output\Output implements OutputInterface
- class \Symfony\Component\Console\Output\StreamOutput
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
File
- vendor/
symfony/ console/ Output/ StreamOutput.php, line 29
Namespace
Symfony\Component\Console\OutputView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Output:: |
private | property | ||
Output:: |
private | property | ||
Output:: |
public | function |
Returns current output formatter instance. Overrides OutputInterface:: |
|
Output:: |
public | function |
Gets the current verbosity of the output. Overrides OutputInterface:: |
|
Output:: |
public | function | ||
Output:: |
public | function |
Gets the decorated flag. Overrides OutputInterface:: |
|
Output:: |
public | function | ||
Output:: |
public | function | ||
Output:: |
public | function | ||
Output:: |
public | function |
Sets the decorated flag. Overrides OutputInterface:: |
1 |
Output:: |
public | function |
Sets output formatter. Overrides OutputInterface:: |
1 |
Output:: |
public | function |
Sets the verbosity of the output. Overrides OutputInterface:: |
1 |
Output:: |
public | function |
Writes a message to the output. Overrides OutputInterface:: |
|
Output:: |
public | function |
Writes a message to the output and adds a newline at the end. Overrides OutputInterface:: |
|
OutputInterface:: |
constant | |||
OutputInterface:: |
constant | |||
OutputInterface:: |
constant | |||
OutputInterface:: |
constant | |||
OutputInterface:: |
constant | |||
OutputInterface:: |
constant | |||
OutputInterface:: |
constant | |||
OutputInterface:: |
constant | |||
StreamOutput:: |
private | property | ||
StreamOutput:: |
protected | function |
Writes a message to the output. Overrides Output:: |
|
StreamOutput:: |
public | function | Gets the stream attached to this StreamOutput instance. | |
StreamOutput:: |
protected | function | Returns true if the stream supports colorization. | |
StreamOutput:: |
public | function |
Constructor. Overrides Output:: |
1 |