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
Output constant for making normal shells.
int 0
Output constants for making quiet shells.
int 2
Output constant making verbose shells.
Cake\Console\ConsoleOutputThe error stream
Cake\Console\HelperRegistryThe helper registry.
Cake\Console\ConsoleInputThe input stream
intThe number of bytes last written to the output stream used when overwriting the previous message.
intThe current output level.
Cake\Console\ConsoleOutputThe output stream
boolWhether files should be overwritten
boolConstructor
Prompts the user for input, and returns it.
Halts the the current process with a StopException.
Prompts the user for input, and returns it.
Prompts the user for input based on a list of options, and returns it.
Convenience method for out() that wraps message between tag
Create a file at the given path.
Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
Convenience method for err() that wraps message between tag
Get defined style.
Render a Console Helper
Outputs a series of minus characters to the standard output, acts as a visual separator.
Convenience method for out() that wraps message between tag
Get/set the current output level.
Returns a single or multiple linefeeds sequences.
Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
Overwrite some already output text.
Output at all levels.
Connects or disconnects the loggers to the console output.
Change the output mode of the stdout stream
Adds a new output style.
Gets defined styles.
Convenience method for out() that wraps message between tag
Output at the verbose level.
Convenience method for err() that wraps message between tag
Wraps a message with a given message type, e.g.
__construct(Cake\Console\ConsoleOutput|null $out = null, Cake\Console\ConsoleOutput|null $err = null, Cake\Console\ConsoleInput|null $in = null, Cake\Console\HelperRegistry|null $helpers = null)
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|null $options, string|null $default): string
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.
stringabort(string $message, int $code = CommandInterface::CODE_ERROR): void
Halts the the current process with a StopException.
string $message Error message.
int $code optional Error code.
voidCake\Console\Exception\StopExceptionask(string $prompt, string|null $default = null): string
Prompts the user for input, and returns it.
string $prompt Prompt text.
string|null $default optional Default input value.
stringaskChoice(string $prompt, array<string>|string $options, string|null $default = null): string
Prompts the user for input based on a list of options, and returns it.
string $prompt Prompt text.
array<string>|string $options Array or string of options.
string|null $default optional Default input value.
stringcomment(array<string>|string $message, int $newlines = 1, int $level = self::NORMAL): int|null
Convenience method for out() that wraps message between tag
array<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|nullcreateFile(string $path, string $contents, bool $forceOverwrite = false): bool
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 the file should be overwritten. If true, no question will be asked about whether to overwrite existing files.
boolCake\Console\Exception\StopExceptionerr(array<string>|string $message = '', int $newlines = 1): int
Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
array<string>|string $message optional A string or an array of strings to output
int $newlines optional Number of newlines to append
interror(array<string>|string $message, int $newlines = 1): int
Convenience method for err() that wraps message between tag
array<string>|string $message A string or an array of strings to output
int $newlines optional Number of newlines to append
intgetStyle(string $style): array
Get defined style.
string $style The style to get.
arrayhelper(string $name, array<string, mixed> $config = []): Cake\Console\Helper
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<string, mixed> $config optional Configuration data for the helper.
Cake\Console\Helperhr(int $newlines = 0, int $width = 79): void
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
voidinfo(array<string>|string $message, int $newlines = 1, int $level = self::NORMAL): int|null
Convenience method for out() that wraps message between tag
array<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|nulllevel(int|null $level = null): int
Get/set the current output level.
int|null $level optional The current output level.
intnl(int $multiplier = 1): string
Returns a single or multiple linefeeds sequences.
int $multiplier optional Number of times the linefeed sequence should be repeated
stringout(array<string>|string $message = '', int $newlines = 1, int $level = self::NORMAL): int|null
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.
array<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|nulloverwrite(array<string>|string $message, int $newlines = 1, int|null $size = null): void
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>|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.
voidquiet(array<string>|string $message, int $newlines = 1): int|null
Output at all levels.
array<string>|string $message A string or an array of strings to output
int $newlines optional Number of newlines to append
int|nullsetInteractive(bool $value): void
bool $value Value
voidsetLoggers(int|bool $enable): void
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.
voidsetOutputAs(int $mode): void
Change the output mode of the stdout stream
int $mode The output mode.
voidsetStyle(string $style, array $definition): void
Adds a new output style.
string $style The style to set.
array $definition The array definition of the style to change or create.
voidstyles(): array
Gets defined styles.
arraysuccess(array<string>|string $message, int $newlines = 1, int $level = self::NORMAL): int|null
Convenience method for out() that wraps message between tag
array<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|nullverbose(array<string>|string $message, int $newlines = 1): int|null
Output at the verbose level.
array<string>|string $message A string or an array of strings to output
int $newlines optional Number of newlines to append
int|nullwarning(array<string>|string $message, int $newlines = 1): int
Convenience method for err() that wraps message between tag
array<string>|string $message A string or an array of strings to output
int $newlines optional Number of newlines to append
intwrapMessageWithType(string $messageType, array<string>|string $message): array<string>|string
Wraps a message with a given message type, e.g.
string $messageType The message type, e.g. "warning".
array<string>|string $message The message to wrap.
array<string>|stringThe error stream
Cake\Console\ConsoleOutputThe helper registry.
Cake\Console\HelperRegistryThe input stream
Cake\Console\ConsoleInputThe number of bytes last written to the output stream used when overwriting the previous message.
intThe current output level.
intThe output stream
Cake\Console\ConsoleOutputWhether files should be overwritten
boolbool
© 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.4/class-Cake.Console.ConsoleIo.html