A wrapper around the various IO operations shell tasks need to do.
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.
int
1
int
0
int
2
\Cake\Console\ConsoleOutput
The error stream
\Cake\Console\HelperRegistry
The helper registry.
\Cake\Console\ConsoleInput
The input stream
int
The number of bytes last written to the output stream used when overwriting the previous message.
int
The current output level.
\Cake\Console\ConsoleOutput
The output stream
bool
Whether or not files should be overwritten
bool
Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
Outputs a series of minus characters to the standard output, acts as a visual separator.
Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
__construct(?\Cake\Console\ConsoleOutput $out, ?\Cake\Console\ConsoleOutput $err, ?\Cake\Console\ConsoleInput $in, ?\Cake\Console\HelperRegistry $helpers)
Constructor
\Cake\Console\ConsoleOutput|null
$out optional A ConsoleOutput object for stdout.
\Cake\Console\ConsoleOutput|null
$err optional A ConsoleOutput object for stderr.
\Cake\Console\ConsoleInput|null
$in optional A ConsoleInput object for stdin.
\Cake\Console\HelperRegistry|null
$helpers optional A HelperRegistry instance
_getInput(string $prompt, ?string $options, ?string $default)
Prompts the user for input, and returns it.
string
$prompt Prompt text.
string|null
$options String of options. Pass null to omit.
string|null
$default Default input value. Pass null to omit.
string
Either the default value, or the user-provided input.
abort(mixed $message, mixed $code)
Halts the the current process with a StopException.
string
$message Error message.
int
$code optional Error code.
Cake\Console\Exception\StopException
ask(string $prompt, ?string $default)
Prompts the user for input, and returns it.
string
$prompt Prompt text.
string|null
$default optional Default input value.
string
Either the default value, or the user-provided input.
askChoice(string $prompt, mixed $options, ?string $default)
Prompts the user for input based on a list of options, and returns it.
string
$prompt Prompt text.
string|array
$options Array or string of options.
string|null
$default optional Default input value.
string
Either the default value, or the user-provided input.
createFile(string $path, string $contents, bool $forceOverwrite)
Create a file at the given path.
This method will prompt the user if a file will be overwritten. Setting forceOverwrite
to true will suppress this behavior and always overwrite the file.
If the user replies a
subsequent forceOverwrite
parameters will be coerced to true and all files will be overwritten.
string
$path The path to create the file at.
string
$contents The contents to put into the file.
bool
$forceOverwrite optional Whether or not the file should be overwritten. If true, no question will be asked about whether or not to overwrite existing files.
bool
Success.
Cake\Console\Exception\StopException
err(mixed $message, int $newlines)
Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
string|string[]
$message optional A string or an array of strings to output
int
$newlines optional Number of newlines to append
int
The number of bytes returned from writing to stderr.
error(mixed $message, int $newlines)
Convenience method for err() that wraps message between tag
string|string[]
$message A string or an array of strings to output
int
$newlines optional Number of newlines to append
int
The number of bytes returned from writing to stderr.
getStyle(string $style)
Get defined style.
string
$style The style to get.
array
helper(string $name, array $settings)
Render a Console 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.
string
$name The name of the helper to render
array
$settings optional Configuration data for the helper.
\Cake\Console\Helper
The created helper instance.
hr(int $newlines, int $width)
Outputs a series of minus characters to the standard output, acts as a visual separator.
int
$newlines optional Number of newlines to pre- and append
int
$width optional Width of the line, defaults to 79
info(mixed $message, int $newlines, int $level)
Convenience method for out() that wraps message between tag
string|string[]
$message A string or an array of strings to output
int
$newlines optional Number of newlines to append
int
$level optional The message's output level, see above.
int|null
The number of bytes returned from writing to stdout or null if provided $level is greater than current level.
level(?int $level)
Get/set the current output level.
int|null
$level optional The current output level.
int
The current output level.
nl(int $multiplier)
Returns a single or multiple linefeeds sequences.
int
$multiplier optional Number of times the linefeed sequence should be repeated
string
out(mixed $message, int $newlines, int $level)
Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
There are 3 built-in output level. ConsoleIo::QUIET, ConsoleIo::NORMAL, ConsoleIo::VERBOSE. The verbose and quiet output levels, map to the verbose
and quiet
output switches present in most shells. Using ConsoleIo::QUIET for a message means it will always display. While using ConsoleIo::VERBOSE means it will only display when verbose output is toggled.
string|string[]
$message optional A string or an array of strings to output
int
$newlines optional Number of newlines to append
int
$level optional The message's output level, see above.
int|null
The number of bytes returned from writing to stdout or null if provided $level is greater than current level.
overwrite(mixed $message, int $newlines, ?int $size)
Overwrite some already output text.
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.
array|string
$message The message to output.
int
$newlines optional Number of newlines to append.
int|null
$size optional The number of bytes to overwrite. Defaults to the length of the last message output.
quiet(mixed $message, int $newlines)
Output at all levels.
string|string[]
$message A string or an array of strings to output
int
$newlines optional Number of newlines to append
int|null
The number of bytes returned from writing to stdout or null if current level is less than ConsoleIo::QUIET
setInteractive(bool $value)
bool
$value Value
setLoggers(mixed $enable)
Connects or disconnects the loggers to the console output.
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
.
int|bool
$enable 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.
setOutputAs(int $mode)
Change the output mode of the stdout stream
int
$mode The output mode.
setStyle(string $style, array $definition)
Adds a new output style.
string
$style The style to set.
array
$definition The array definition of the style to change or create.
styles()
Gets defined styles.
array
success(mixed $message, int $newlines, int $level)
Convenience method for out() that wraps message between tag
string|string[]
$message A string or an array of strings to output
int
$newlines optional Number of newlines to append
int
$level optional The message's output level, see above.
int|null
The number of bytes returned from writing to stdout or null if provided $level is greater than current level.
verbose(mixed $message, int $newlines)
Output at the verbose level.
string|string[]
$message A string or an array of strings to output
int
$newlines optional Number of newlines to append
int|null
The number of bytes returned from writing to stdout or null if current level is less than ConsoleIo::VERBOSE
warning(mixed $message, int $newlines)
Convenience method for err() that wraps message between tag
string|string[]
$message A string or an array of strings to output
int
$newlines optional Number of newlines to append
int
The number of bytes returned from writing to stderr.
wrapMessageWithType(string $messageType, mixed $message)
Wraps a message with a given message type, e.g.
string
$messageType The message type, e.g. "warning".
string|string[]
$message The message to wrap.
string|string[]
The message wrapped with the given message type.
The error stream
\Cake\Console\ConsoleOutput
The helper registry.
\Cake\Console\HelperRegistry
The input stream
\Cake\Console\ConsoleInput
The number of bytes last written to the output stream used when overwriting the previous message.
int
The current output level.
int
The output stream
\Cake\Console\ConsoleOutput
Whether or not files should be overwritten
bool
bool
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Console.ConsoleIo.html