PHP Класс Cake\Console\ConsoleIo

Packages up the stdout, stderr, and stdin streams providing a simple consistent interface for shells to use. This class also makes mocking streams easy to do in unit tests.
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$_err ConsoleOutput The error stream
$_helpers Cake\Console\HelperRegistry The helper registry.
$_in Cake\Console\ConsoleInput The input stream
$_lastWritten integer The number of bytes last written to the output stream used when overwriting the previous message.
$_level integer The current output level.
$_out ConsoleOutput The output stream

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

Метод Описание
__construct ( ConsoleOutput $out = null, ConsoleOutput $err = null, Cake\Console\ConsoleInput $in = null, Cake\Console\HelperRegistry $helpers = null ) Constructor
ask ( string $prompt, string | null $default = null ) : mixed Prompts the user for input, and returns it.
askChoice ( string $prompt, string | array $options, string | null $default = null ) : mixed Prompts the user for input based on a list of options, and returns it.
err ( string | array $message = '', integer $newlines = 1 ) : integer | boolean Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
helper ( string $name, array $settings = [] ) : Cake\Console\Helper Render a Console Helper
hr ( integer $newlines, integer $width = 79 ) : void Outputs a series of minus characters to the standard output, acts as a visual separator.
level ( null | integer $level = null ) : integer Get/set the current output level.
nl ( integer $multiplier = 1 ) : string Returns a single or multiple linefeeds sequences.
out ( string | array $message = '', integer $newlines = 1, integer $level = ConsoleIo::NORMAL ) : integer | boolean Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
outputAs ( integer $mode ) : void Change the output mode of the stdout stream
overwrite ( array | string $message, integer $newlines = 1, integer | null $size = null ) : void Overwrite some already output text.
quiet ( string | array $message, integer $newlines = 1 ) : integer | boolean Output at all levels.
setLoggers ( integer | boolean $enable ) : void Connects or disconnects the loggers to the console output.
styles ( string | null $style = null, array | boolean | null $definition = null ) : mixed Add a new output style or get defined styles.
verbose ( string | array $message, integer $newlines = 1 ) : integer | boolean Output at the verbose level.

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

Метод Описание
_getInput ( string $prompt, string | null $options, string | null $default ) : string Prompts the user for input, and returns it.

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

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

Constructor
public __construct ( ConsoleOutput $out = null, ConsoleOutput $err = null, Cake\Console\ConsoleInput $in = null, Cake\Console\HelperRegistry $helpers = null )
$out ConsoleOutput A ConsoleOutput object for stdout.
$err ConsoleOutput A ConsoleOutput object for stderr.
$in Cake\Console\ConsoleInput A ConsoleInput object for stdin.
$helpers Cake\Console\HelperRegistry A HelperRegistry instance

_getInput() защищенный Метод

Prompts the user for input, and returns it.
protected _getInput ( string $prompt, string | null $options, string | null $default ) : string
$prompt string Prompt text.
$options string | null String of options. Pass null to omit.
$default string | null Default input value. Pass null to omit.
Результат string Either the default value, or the user-provided input.

ask() публичный Метод

Prompts the user for input, and returns it.
public ask ( string $prompt, string | null $default = null ) : mixed
$prompt string Prompt text.
$default string | null Default input value.
Результат mixed Either the default value, or the user-provided input.

askChoice() публичный Метод

Prompts the user for input based on a list of options, and returns it.
public askChoice ( string $prompt, string | array $options, string | null $default = null ) : mixed
$prompt string Prompt text.
$options string | array Array or string of options.
$default string | null Default input value.
Результат mixed Either the default value, or the user-provided input.

err() публичный Метод

Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
public err ( 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 stderr.

helper() публичный Метод

Create and render the output for a helper object. If the helper object has not already been loaded, it will be loaded and constructed.
public helper ( string $name, array $settings = [] ) : Cake\Console\Helper
$name string The name of the helper to render
$settings array Configuration data for the helper.
Результат Cake\Console\Helper The created helper instance.

hr() публичный Метод

Outputs a series of minus characters to the standard output, acts as a visual separator.
public hr ( integer $newlines, integer $width = 79 ) : void
$newlines integer Number of newlines to pre- and append
$width integer Width of the line, defaults to 79
Результат void

level() публичный Метод

Get/set the current output level.
public level ( null | integer $level = null ) : integer
$level null | integer The current output level.
Результат integer The current output level.

nl() публичный Метод

Returns a single or multiple linefeeds sequences.
public nl ( integer $multiplier = 1 ) : string
$multiplier integer Number of times the linefeed sequence should be repeated
Результат string

out() публичный Метод

### Output levels There are 3 built-in output level. Shell::QUIET, Shell::NORMAL, Shell::VERBOSE. The verbose and quiet output levels, map to the verbose and quiet output switches present in most shells. Using Shell::QUIET for a message means it will always display. While using Shell::VERBOSE means it will only display when verbose output is toggled.
public out ( string | array $message = '', integer $newlines = 1, integer $level = ConsoleIo::NORMAL ) : integer | boolean
$message string | array A string or an array of strings to output
$newlines integer Number of newlines to append
$level integer The message's output level, see above.
Результат integer | boolean The number of bytes returned from writing to stdout.

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

Change the output mode of the stdout stream
См. также: Cake\Console\ConsoleOutput::outputAs()
public outputAs ( integer $mode ) : void
$mode integer The output mode.
Результат void

overwrite() публичный Метод

Useful for building progress bars, or when you want to replace text already output to the screen with new text. **Warning** You cannot overwrite text that contains newlines.
public overwrite ( array | string $message, integer $newlines = 1, integer | null $size = null ) : void
$message array | string The message to output.
$newlines integer Number of newlines to append.
$size integer | null The number of bytes to overwrite. Defaults to the length of the last message output.
Результат void

quiet() публичный Метод

Output at all levels.
public quiet ( 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 stdout.

setLoggers() публичный Метод

Used to enable or disable logging stream output to stdout and stderr If you don't wish all log output in stdout or stderr through Cake's Log class, call this function with $enable=false.
public setLoggers ( integer | boolean $enable ) : void
$enable integer | boolean Use a boolean to enable/toggle all logging. Use one of the verbosity constants (self::VERBOSE, self::QUIET, self::NORMAL) to control logging levels. VERBOSE enables debug logs, NORMAL does not include debug logs, QUIET disables notice, info and debug logs.
Результат void

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

Add a new output style or get defined styles.
См. также: Cake\Console\ConsoleOutput::styles()
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.

verbose() публичный Метод

Output at the verbose level.
public verbose ( 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 stdout.

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

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

The error stream
protected ConsoleOutput,Cake\Console $_err
Результат ConsoleOutput

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

The helper registry.
protected HelperRegistry,Cake\Console $_helpers
Результат Cake\Console\HelperRegistry

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

The input stream
protected ConsoleInput,Cake\Console $_in
Результат Cake\Console\ConsoleInput

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

The number of bytes last written to the output stream used when overwriting the previous message.
protected int $_lastWritten
Результат integer

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

The current output level.
protected int $_level
Результат integer

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

The output stream
protected ConsoleOutput,Cake\Console $_out
Результат ConsoleOutput