PHP Class 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.
Datei anzeigen Open project: cakephp/cakephp Class Usage Examples

Protected Properties

Property Type Description
$_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

Public Methods

Method Description
__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.

Protected Methods

Method Description
_getInput ( string $prompt, string | null $options, string | null $default ) : string Prompts the user for input, and returns it.

Method Details

__construct() public method

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() protected method

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.
return string Either the default value, or the user-provided input.

ask() public method

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.
return mixed Either the default value, or the user-provided input.

askChoice() public method

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.
return mixed Either the default value, or the user-provided input.

err() public method

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
return integer | boolean The number of bytes returned from writing to stderr.

helper() public method

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.
return Cake\Console\Helper The created helper instance.

hr() public method

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
return void

level() public method

Get/set the current output level.
public level ( null | integer $level = null ) : integer
$level null | integer The current output level.
return integer The current output level.

nl() public method

Returns a single or multiple linefeeds sequences.
public nl ( integer $multiplier = 1 ) : string
$multiplier integer Number of times the linefeed sequence should be repeated
return string

out() public method

### 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.
return integer | boolean The number of bytes returned from writing to stdout.

outputAs() public method

Change the output mode of the stdout stream
See also: Cake\Console\ConsoleOutput::outputAs()
public outputAs ( integer $mode ) : void
$mode integer The output mode.
return void

overwrite() public method

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.
return void

quiet() public method

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
return integer | boolean The number of bytes returned from writing to stdout.

setLoggers() public method

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.
return void

styles() public method

Add a new output style or get defined styles.
See also: 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.
return mixed If you are getting styles, the style or null will be returned. If you are creating/modifying styles true will be returned.

verbose() public method

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
return integer | boolean The number of bytes returned from writing to stdout.

Property Details

$_err protected_oe property

The error stream
protected ConsoleOutput,Cake\Console $_err
return ConsoleOutput

$_helpers protected_oe property

The helper registry.
protected HelperRegistry,Cake\Console $_helpers
return Cake\Console\HelperRegistry

$_in protected_oe property

The input stream
protected ConsoleInput,Cake\Console $_in
return Cake\Console\ConsoleInput

$_lastWritten protected_oe property

The number of bytes last written to the output stream used when overwriting the previous message.
protected int $_lastWritten
return integer

$_level protected_oe property

The current output level.
protected int $_level
return integer

$_out protected_oe property

The output stream
protected ConsoleOutput,Cake\Console $_out
return ConsoleOutput