PHP Класс 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.
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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()

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
_replaceTags ( array $matches ) : string Replace tags with color codes.
_write ( string $message ) : integer | boolean Writes a message to the output stream.

Описание методов

__construct() публичный метод

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() публичный метод

Clean up and close handles
public __destruct ( )

_replaceTags() защищенный метод

Replace tags with color codes.
protected _replaceTags ( array $matches ) : string
$matches array An array of matches to replace.
Результат string

_write() защищенный метод

Writes a message to the output stream.
protected _write ( string $message ) : integer | boolean
$message string Message to write.
Результат integer | boolean The number of bytes returned from writing to output.

outputAs() публичный метод

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.
Результат integer | null Either null or the value if getting.

styleText() публичный метод

Apply styling to text.
public styleText ( string $text ) : string
$text string Text with styling tags.
Результат string String with color codes added.

styles() публичный метод

### 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.
Результат mixed If you are getting styles, the style or null will be returned. If you are creating/modifying styles true will be returned.

write() публичный метод

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
Результат integer | boolean The number of bytes returned from writing to output.

Описание свойств

$_backgroundColors защищенное статическое свойство

background colors used in colored output.
protected static array $_backgroundColors
Результат array

$_foregroundColors защищенное статическое свойство

text colors used in colored output.
protected static array $_foregroundColors
Результат array

$_options защищенное статическое свойство

formatting options for colored output
protected static string $_options
Результат string

$_output защищенное свойство

File handle for output.
protected resource $_output
Результат resource

$_outputAs защищенное свойство

The current output type. Manipulated with ConsoleOutput::outputAs();
protected int $_outputAs
Результат integer

$_styles защищенное статическое свойство

You can modify these styles with ConsoleOutput::styles()
protected static array $_styles
Результат array