Input
in package
Handles input parsing and retrieval for CLI commands.
Processes command-line arguments and options.
Table of Contents
Properties
- $arguments : array<string|int, mixed>
- $argv : array<string|int, mixed>
- $options : array<string|int, mixed>
- $rawArguments : array<string|int, mixed>
- $stream : StreamInterface
Methods
- __construct() : mixed
- ask() : string
- Ask a question and return the answer
- askSecret() : string
- Ask for secret input (e.g., passwords) with hidden characters
- choice() : string|array<string|int, mixed>
- Ask the user to choose from a list of options
- confirm() : bool
- Ask a yes/no question
- getArgument() : mixed
- Get an argument value
- getArguments() : array<string|int, mixed>
- Get all arguments
- getArgv() : array<string|int, mixed>
- Get the original argv array
- getOption() : mixed
- Get an option value
- getOptions() : array<string|int, mixed>
- Get all options
- getRawArguments() : array<string|int, mixed>
- Get the raw arguments array
- hasArgument() : bool
- Check if an argument exists
- hasOption() : bool
- Check if an option exists
- isInteractive() : bool
- Check if input is interactive (connected to a TTY)
- parse() : void
- Parse input according to command configuration
- readLine() : string|false
- Read a line from standard input
- setArgument() : void
- Set an argument value
- setOption() : void
- Set an option value
- parseChoice() : string|null
- Parse a single choice input
- parseRaw() : void
- Parse raw input into arguments and options
Properties
$arguments
private
array<string|int, mixed>
$arguments
= []
$argv
private
array<string|int, mixed>
$argv
$options
private
array<string|int, mixed>
$options
= []
$rawArguments
private
array<string|int, mixed>
$rawArguments
= []
$stream
private
StreamInterface
$stream
Methods
__construct()
public
__construct([array<string|int, mixed> $argv = [] ][, StreamInterface|null $stream = null ]) : mixed
Parameters
- $argv : array<string|int, mixed> = []
-
Command-line arguments (without script name)
- $stream : StreamInterface|null = null
-
Stream for interactive I/O (null = use standard streams)
ask()
Ask a question and return the answer
public
ask(string $question[, string|null $default = null ]) : string
Parameters
- $question : string
- $default : string|null = null
Return values
stringaskSecret()
Ask for secret input (e.g., passwords) with hidden characters
public
askSecret(string $question) : string
Parameters
- $question : string
Return values
stringchoice()
Ask the user to choose from a list of options
public
choice(string $question, array<string|int, mixed> $choices[, mixed $default = null ][, bool $allowMultiple = false ]) : string|array<string|int, mixed>
Parameters
- $question : string
- $choices : array<string|int, mixed>
-
Array of choices (can be associative)
- $default : mixed = null
-
Default choice (key or value)
- $allowMultiple : bool = false
-
Allow multiple selections
Return values
string|array<string|int, mixed> —Single choice or array of choices if multiple allowed
confirm()
Ask a yes/no question
public
confirm(string $question[, bool $default = false ]) : bool
Parameters
- $question : string
- $default : bool = false
Return values
boolgetArgument()
Get an argument value
public
getArgument(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
getArguments()
Get all arguments
public
getArguments() : array<string|int, mixed>
Return values
array<string|int, mixed>getArgv()
Get the original argv array
public
getArgv() : array<string|int, mixed>
Return values
array<string|int, mixed>getOption()
Get an option value
public
getOption(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
getOptions()
Get all options
public
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getRawArguments()
Get the raw arguments array
public
getRawArguments() : array<string|int, mixed>
Return values
array<string|int, mixed>hasArgument()
Check if an argument exists
public
hasArgument(string $name) : bool
Parameters
- $name : string
Return values
boolhasOption()
Check if an option exists
public
hasOption(string $name) : bool
Parameters
- $name : string
Return values
boolisInteractive()
Check if input is interactive (connected to a TTY)
public
isInteractive() : bool
Return values
boolparse()
Parse input according to command configuration
public
parse(Command $command) : void
Parameters
- $command : Command
readLine()
Read a line from standard input
public
readLine([string $prompt = '' ]) : string|false
Parameters
- $prompt : string = ''
-
Optional prompt to display
Return values
string|falsesetArgument()
Set an argument value
public
setArgument(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
setOption()
Set an option value
public
setOption(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
parseChoice()
Parse a single choice input
private
parseChoice(string $input, array<string|int, mixed> $choices, array<string|int, mixed> $indexMap) : string|null
Parameters
- $input : string
- $choices : array<string|int, mixed>
- $indexMap : array<string|int, mixed>
Return values
string|nullparseRaw()
Parse raw input into arguments and options
private
parseRaw() : void