class StreamOutput extends Output

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));

Methods

__construct(resource $stream, int|null $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null)

No description

setFormatter(OutputFormatterInterface $formatter)

No description

from Output
getFormatter()

Returns current output formatter instance.

from Output
setDecorated(bool $decorated)

Sets the decorated flag.

from Output
bool
isDecorated()

Gets the decorated flag.

from Output
setVerbosity(int $level)

Sets the verbosity of the output.

from Output
int
getVerbosity()

Gets the current verbosity of the output.

from Output
bool
isQuiet()

Returns whether verbosity is quiet (-q).

from Output
bool
isVerbose()

Returns whether verbosity is verbose (-v).

from Output
bool
isVeryVerbose()

Returns whether verbosity is very verbose (-vv).

from Output
bool
isDebug()

Returns whether verbosity is debug (-vvv).

from Output
writeln(string|iterable $messages, int $options = self::OUTPUT_NORMAL)

Writes a message to the output and adds a newline at the end.

from Output
write(string|iterable $messages, bool $newline = false, int $options = self::OUTPUT_NORMAL)

Writes a message to the output.

from Output
doWrite(string $message, bool $newline)

Writes a message to the output.

resource
getStream()

Gets the stream attached to this StreamOutput instance.

bool
hasColorSupport()

Returns true if the stream supports colorization.

Details

__construct(resource $stream, int|null $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null)

Parameters

resource $stream A stream resource
int|null $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
bool $decorated Whether to decorate messages
OutputFormatterInterface $formatter Output formatter instance (null to use default OutputFormatter)

Exceptions

InvalidArgumentException When first argument is not a real stream

setFormatter(OutputFormatterInterface $formatter)

Parameters

OutputFormatterInterface $formatter

OutputFormatterInterface getFormatter()

Returns current output formatter instance.

setDecorated(bool $decorated)

Sets the decorated flag.

Parameters

bool $decorated Whether to decorate the messages

bool isDecorated()

Gets the decorated flag.

Return Value

bool true if the output will decorate messages, false otherwise

setVerbosity(int $level)

Sets the verbosity of the output.

Parameters

int $level The level of verbosity (one of the VERBOSITY constants)

int getVerbosity()

Gets the current verbosity of the output.

Return Value

int The current level of verbosity (one of the VERBOSITY constants)

bool isQuiet()

Returns whether verbosity is quiet (-q).

Return Value

bool true if verbosity is set to VERBOSITY_QUIET, false otherwise

bool isVerbose()

Returns whether verbosity is verbose (-v).

Return Value

bool true if verbosity is set to VERBOSITY_VERBOSE, false otherwise

bool isVeryVerbose()

Returns whether verbosity is very verbose (-vv).

Return Value

bool true if verbosity is set to VERBOSITY_VERY_VERBOSE, false otherwise

bool isDebug()

Returns whether verbosity is debug (-vvv).

Return Value

bool true if verbosity is set to VERBOSITY_DEBUG, false otherwise

writeln(string|iterable $messages, int $options = self::OUTPUT_NORMAL)

Writes a message to the output and adds a newline at the end.

Parameters

string|iterable $messages The message as an iterable of strings or a single string
int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL

write(string|iterable $messages, bool $newline = false, int $options = self::OUTPUT_NORMAL)

Writes a message to the output.

Parameters

string|iterable $messages The message as an iterable of strings or a single string
bool $newline Whether to add a newline
int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL

protected doWrite(string $message, bool $newline)

Writes a message to the output.

Parameters

string $message A message to write to the output
bool $newline Whether to add a newline or not

resource getStream()

Gets the stream attached to this StreamOutput instance.

Return Value

resource A stream resource

protected bool hasColorSupport()

Returns true if the stream supports colorization.

Colorization is disabled if not supported by the stream:

This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo terminals via named pipes, so we can only check the environment.

Reference: Composer\XdebugHandler\Process::supportsColor https://github.com/composer/xdebug-handler

Return Value

bool true if the stream supports colorization, false otherwise