PHP Class Cake\Console\ConsoleOutput

Can be connected to any stream resource that can be used with fopen() Can generate colorized output on consoles that support it. There are a few built in styles - error Error messages. - warning Warning messages. - info Informational messages. - comment Additional text. - question Magenta text used for user prompts By defining styles with addStyle() you can create custom console styles. ### Using styles in output You can format console output using tags with the name of the style to apply. From inside a shell object $this->out('Overwrite: foo.php was overwritten.'); This would create orange 'Overwrite:' text, while the rest of the text would remain the normal color. See ConsoleOutput::styles() to learn more about defining your own styles. Nested styles are not supported at this time.
Datei anzeigen Open project: cakephp/cakephp Class Usage Examples

Protected Properties

Property Type Description
$_backgroundColors array background colors used in colored output.
$_foregroundColors array text colors used in colored output.
$_options string formatting options for colored output
$_output resource File handle for output.
$_outputAs integer The current output type. Manipulated with ConsoleOutput::outputAs();
$_styles array You can modify these styles with ConsoleOutput::styles()

Public Methods

Method Description
__construct ( string $stream = 'php://stdout' ) Construct the output object.
__destruct ( ) Clean up and close handles
outputAs ( integer | null $type = null ) : integer | null Get/Set the output type to use. The output type how formatting tags are treated.
styleText ( string $text ) : string Apply styling to text.
styles ( string | null $style = null, array | boolean | null $definition = null ) : mixed Get the current styles offered, or append new ones in.
write ( string | array $message, integer $newlines = 1 ) : integer | boolean Outputs a single or multiple messages to stdout or stderr. If no parameters are passed, outputs just a newline.

Protected Methods

Method Description
_replaceTags ( array $matches ) : string Replace tags with color codes.
_write ( string $message ) : integer | boolean Writes a message to the output stream.

Method Details

__construct() public method

Checks for a pretty console environment. Ansicon and ConEmu allows pretty consoles on windows, and is supported.
public __construct ( string $stream = 'php://stdout' )
$stream string The identifier of the stream to write output to.

__destruct() public method

Clean up and close handles
public __destruct ( )

_replaceTags() protected method

Replace tags with color codes.
protected _replaceTags ( array $matches ) : string
$matches array An array of matches to replace.
return string

_write() protected method

Writes a message to the output stream.
protected _write ( string $message ) : integer | boolean
$message string Message to write.
return integer | boolean The number of bytes returned from writing to output.

outputAs() public method

Get/Set the output type to use. The output type how formatting tags are treated.
public outputAs ( integer | null $type = null ) : integer | null
$type integer | null The output type to use. Should be one of the class constants.
return integer | null Either null or the value if getting.

styleText() public method

Apply styling to text.
public styleText ( string $text ) : string
$text string Text with styling tags.
return string String with color codes added.

styles() public method

### Get a style definition $output->styles('error'); ### Get all the style definitions $output->styles(); ### Create or modify an existing style $output->styles('annoy', ['text' => 'purple', 'background' => 'yellow', 'blink' => true]); ### Remove a style $this->output->styles('annoy', false);
public styles ( string | null $style = null, array | boolean | null $definition = null ) : mixed
$style string | null The style to get or create.
$definition array | boolean | null The array definition of the style to change or create a style or false to remove a style.
return mixed If you are getting styles, the style or null will be returned. If you are creating/modifying styles true will be returned.

write() public method

Outputs a single or multiple messages to stdout or stderr. If no parameters are passed, outputs just a newline.
public write ( string | array $message, integer $newlines = 1 ) : integer | boolean
$message string | array A string or an array of strings to output
$newlines integer Number of newlines to append
return integer | boolean The number of bytes returned from writing to output.

Property Details

$_backgroundColors protected_oe static_oe property

background colors used in colored output.
protected static array $_backgroundColors
return array

$_foregroundColors protected_oe static_oe property

text colors used in colored output.
protected static array $_foregroundColors
return array

$_options protected_oe static_oe property

formatting options for colored output
protected static string $_options
return string

$_output protected_oe property

File handle for output.
protected resource $_output
return resource

$_outputAs protected_oe property

The current output type. Manipulated with ConsoleOutput::outputAs();
protected int $_outputAs
return integer

$_styles protected_oe static_oe property

You can modify these styles with ConsoleOutput::styles()
protected static array $_styles
return array