Object wrapper for outputting information from a shell application.
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 promptsBy defining styles with addStyle() you can create custom console styles.
You can format console output using tags with the name of the style to apply. From inside a shell object
$this->out('<warning>Overwrite:</warning> 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.
int
2
string
PHP_EOL
int
1
int
0
array
background colors used in colored output.
array
text colors used in colored output.
array
Formatting options for colored output.
resource
File handle for output.
int
The current output type.
array
Styles that are available as tags in console output.
Outputs a single or multiple messages to stdout or stderr. If no parameters are passed, outputs just a newline.
__construct(string $stream)
Construct the output object.
Checks for a pretty console environment. Ansicon and ConEmu allows pretty consoles on windows, and is supported.
string
$stream optional The identifier of the stream to write output to.
__destruct()
Clean up and close handles
_replaceTags(array $matches)
Replace tags with color codes.
array
$matches An array of matches to replace.
string
_write(string $message)
Writes a message to the output stream.
string
$message Message to write.
int
The number of bytes returned from writing to output.
getOutputAs()
Get the output type on how formatting tags are treated.
int
getStyle(string $style)
Gets the current styles offered
string
$style The style to get.
array
The style or empty array.
setOutputAs(int $type)
Set the output type on how formatting tags are treated.
int
$type The output type to use. Should be one of the class constants.
InvalidArgumentException
setStyle(string $style, array $definition)
Sets style.
$output->setStyle('annoy', ['text' => 'purple', 'background' => 'yellow', 'blink' => true]);
$this->output->setStyle('annoy', []);
string
$style The style to set.
array
$definition The array definition of the style to change or create..
styleText(string $text)
Apply styling to text.
string
$text Text with styling tags.
string
String with color codes added.
styles()
Gets all the style definitions.
array
write(mixed $message, int $newlines)
Outputs a single or multiple messages to stdout or stderr. If no parameters are passed, outputs just a newline.
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 output.
background colors used in colored output.
array
text colors used in colored output.
array
Formatting options for colored output.
array
File handle for output.
resource
The current output type.
int
Styles that are available as tags in console output.
You can modify these styles with ConsoleOutput::styles()
array
© 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.ConsoleOutput.html