-
Notifications
You must be signed in to change notification settings - Fork 51
Input And Output
Joe Huss edited this page Sep 4, 2021
·
2 revisions
Inside the lifecycle hooks of the application or any command, there are several methods available to collect input and write output.
There are several methods that can collect input. Those methods will then return the value which you can store in a variable. The following methods are available:
Method | Description |
---|---|
$this->ask('Question?') (new Prompter())->ask('Question?')
|
Let the user type in any value. |
$this->ask('Question?', $values) (new Prompter())->ask('Question?', $values)
|
Repeat question until user enters one of the specified values. |
(new Prompter())->ask('Question?', $values, $default) |
Repeat question until user enters one of the specified values or an empty string (= $default ). |
(new Prompter())->password('Question?') |
Let the user type in any value and do not show what the user is typing. |
$this->choose('Question?', $values) (new Chooser())->choose('Question?', $values)
|
Repeat question and values until user enters a number associated with a value. |
Both Prompter
and Chooser
have a setStyle($style)
method to set the style that is passed to the formatter.
Output can be created using $this->getLogger()
. The available methods correspond with the different log levels, e.g. $this->getLogger()->info('Hello World!')
.
Available log levels:
- critical
- error
- warn
- info
- info2
- debug
- debug2
Additional methods:
Method | Description |
---|---|
getLevelByName($levelName) |
Returns a number associated with the level name. |
setLevel($levelNr) |
Hides any output higher (more detailed) than this level. Defaults to the number associated with info . |
indent($amount) |
Increases indent of next output by amount. |
unIndent($amount) |
Decreases indent of next output by amount. |
resetIndent() |
Set indent to 0. |
write($text) |
Writes unformatted text to output. |
writln($text) |
Writes unformatted text and a newline character to output. |
newline() |
Writes a newline character to output. |
logException($exception) |
Writes the unformatted exception message to output. |