StdinInputReader
in package
implements
IInputReader
Production input reader that reads from STDIN.
This is the default input reader used by CLI commands in production. It reads actual user input from the standard input stream.
Table of Contents
Interfaces
- IInputReader
- Interface for reading user input in CLI commands.
Constants
- MAX_RETRY_ATTEMPTS = 10
- Maximum number of retry attempts for invalid input.
Properties
Methods
- __construct() : mixed
- 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.
- isTty() : bool
- Check if STDIN is a TTY (terminal).
Constants
MAX_RETRY_ATTEMPTS
Maximum number of retry attempts for invalid input.
private
mixed
MAX_RETRY_ATTEMPTS
= 10
After this many failed attempts, the method will fall back to the default or throw an exception if no default is provided.
Properties
$output
private
Output
$output
Methods
__construct()
public
__construct(Output $output) : mixed
Parameters
- $output : Output
-
Output instance for displaying prompts
choice()
Prompt user to select from a list of options.
public
choice(string $message, array<string|int, mixed> $options[, string|null $default = null ]) : string
Parameters
- $message : string
-
The prompt message
- $options : array<string|int, mixed>
-
Available options
- $default : string|null = null
-
Default option (will be marked with *)
Tags
Return values
string —The selected option
confirm()
Ask user for yes/no confirmation.
public
confirm(string $message[, bool $default = false ]) : bool
Parameters
- $message : string
-
The confirmation message
- $default : bool = false
-
Default value if user just presses enter
Tags
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
Tags
Return values
string —The user's response (trimmed)
secret()
Prompt for sensitive input without echoing to console.
public
secret(string $message) : string
Parameters
- $message : string
-
The prompt message
Tags
Return values
string —The user's input (trimmed)
isTty()
Check if STDIN is a TTY (terminal).
private
isTty() : bool
This prevents stty errors when running in non-interactive environments like CI/CD pipelines, automated scripts, or with piped input.
Return values
bool —True if STDIN is a TTY, false otherwise