IInputReader
in
Interface for reading user input in CLI commands.
Provides an abstraction over STDIN to enable testable CLI commands. Implementations can read from actual user input (StdinInputReader) or from pre-programmed responses (TestInputReader) for testing.
Table of Contents
Methods
- choice() : string
- Prompt user to select from a list of options.
- confirm() : bool
- Ask user for yes/no confirmation.
- prompt() : string
- Prompt user for input and return their response.
- secret() : string
- Prompt for sensitive input without echoing to console.
Methods
choice()
Prompt user to select from a list of options.
public
choice(string $message, array<string|int, string> $options[, string|null $default = null ]) : string
Users can select by entering either the option index (numeric) or the exact option text.
Parameters
- $message : string
-
The prompt message
- $options : array<string|int, string>
-
Available options
- $default : string|null = null
-
Default option (will be marked with *)
Return values
string —The selected option
confirm()
Ask user for yes/no confirmation.
public
confirm(string $message[, bool $default = false ]) : bool
Accepts: y, yes, true, 1 (case-insensitive) as positive responses. All other inputs are treated as negative responses.
Parameters
- $message : string
-
The confirmation message
- $default : bool = false
-
Default value if user just presses enter
Return values
bool —True if user confirms, false otherwise
prompt()
Prompt user for input and return their response.
public
prompt(string $message) : string
Parameters
- $message : string
-
The prompt message to display
Return values
string —The user's response (trimmed)
secret()
Prompt for sensitive input without echoing to console.
public
secret(string $message) : string
Note: Secret input is only supported on Unix-like systems. On Windows, input will be visible.
Parameters
- $message : string
-
The prompt message
Return values
string —The user's input (trimmed)