ArgvInput
extends Input
in package
ArgvInput represents an input coming from the CLI arguments.
Usage:
$input = new ArgvInput();
By default, the $_SERVER['argv']
array is used for the input values.
This can be overridden by explicitly passing the input values in the constructor:
$input = new ArgvInput($_SERVER['argv']);
If you pass it yourself, don't forget that the first element of the array is the name of the running application.
When passing an argument to the constructor, be sure that it respects
the same rules as the argv one. It's almost always better to use the
StringInput
when you want to provide your own input.
Tags
Table of Contents
Properties
- $arguments : mixed
- $definition : mixed
- $interactive : mixed
- $options : mixed
- $stream : mixed
- $parsed : mixed
- $tokens : mixed
Methods
- __construct() : mixed
- __toString() : string
- Returns a stringified representation of the args passed to the command.
- bind() : mixed
- Binds the current Input instance with the given arguments and options.
- escapeToken() : string
- Escapes a token through escapeshellarg if it contains unsafe chars.
- getArgument() : mixed
- Returns the argument value for a given argument name.
- getArguments() : array<string|int, string|bool|int|float|array<string|int, mixed>|null>
- Returns all the given arguments merged with the default values.
- getFirstArgument() : string|null
- Returns the first argument from the raw parameters (not parsed).
- getOption() : mixed
- Returns the option value for a given option name.
- getOptions() : array<string|int, string|bool|int|float|array<string|int, mixed>|null>
- Returns all the given options merged with the default values.
- getParameterOption() : mixed
- Returns the value of a raw option (not parsed).
- getStream() : resource|null
- Returns the input stream.
- hasArgument() : bool
- Returns true if an InputArgument object exists by name or position.
- hasOption() : bool
- Returns true if an InputOption object exists by name.
- hasParameterOption() : bool
- Returns true if the raw parameters (not parsed) contain a value.
- isInteractive() : bool
- Is this input means interactive?
- setArgument() : mixed
- Sets an argument value by name.
- setInteractive() : mixed
- Sets the input interactivity.
- setOption() : mixed
- Sets an option value by name.
- setStream() : mixed
- Sets the input stream to read from when interacting with the user.
- validate() : mixed
- Validates the input.
- parse() : mixed
- Processes command line arguments.
- setTokens() : mixed
- addLongOption() : mixed
- Adds a long option value.
- addShortOption() : mixed
- Adds a short option value.
- parseArgument() : mixed
- Parses an argument.
- parseLongOption() : mixed
- Parses a long option.
- parseShortOption() : mixed
- Parses a short option.
- parseShortOptionSet() : mixed
- Parses a short option set.
Properties
$arguments
protected
mixed
$arguments
= []
$definition
protected
mixed
$definition
$interactive
protected
mixed
$interactive
= true
$options
protected
mixed
$options
= []
$stream
protected
mixed
$stream
$parsed
private
mixed
$parsed
$tokens
private
mixed
$tokens
Methods
__construct()
public
__construct([array<string|int, mixed>|null $argv = null ][, InputDefinition $definition = null ]) : mixed
Parameters
- $argv : array<string|int, mixed>|null = null
-
An array of parameters from the CLI (in the argv format)
- $definition : InputDefinition = null
__toString()
Returns a stringified representation of the args passed to the command.
public
__toString() : string
Return values
stringbind()
Binds the current Input instance with the given arguments and options.
public
bind(InputDefinition $definition) : mixed
Parameters
- $definition : InputDefinition
escapeToken()
Escapes a token through escapeshellarg if it contains unsafe chars.
public
escapeToken(string $token) : string
Parameters
- $token : string
Return values
stringgetArgument()
Returns the argument value for a given argument name.
public
getArgument(mixed $name) : mixed
Parameters
- $name : mixed
-
The argument name
getArguments()
Returns all the given arguments merged with the default values.
public
getArguments() : array<string|int, string|bool|int|float|array<string|int, mixed>|null>
Return values
array<string|int, string|bool|int|float|array<string|int, mixed>|null>getFirstArgument()
Returns the first argument from the raw parameters (not parsed).
public
getFirstArgument() : string|null
Return values
string|null —The value of the first argument or null otherwise
getOption()
Returns the option value for a given option name.
public
getOption(mixed $name) : mixed
Parameters
- $name : mixed
-
The option name
getOptions()
Returns all the given options merged with the default values.
public
getOptions() : array<string|int, string|bool|int|float|array<string|int, mixed>|null>
Return values
array<string|int, string|bool|int|float|array<string|int, mixed>|null>getParameterOption()
Returns the value of a raw option (not parsed).
public
getParameterOption(mixed $values[, mixed $default = false ][, mixed $onlyParams = false ]) : mixed
Parameters
- $values : mixed
-
The value(s) to look for in the raw parameters (can be an array)
- $default : mixed = false
-
The default value to return if no result is found
- $onlyParams : mixed = false
-
Only check real parameters, skip those following an end of options (--) signal
Return values
mixed —The option value
getStream()
Returns the input stream.
public
getStream() : resource|null
Return values
resource|nullhasArgument()
Returns true if an InputArgument object exists by name or position.
public
hasArgument(mixed $name) : bool
Parameters
- $name : mixed
-
The argument name
Return values
bool —true if the InputArgument object exists, false otherwise
hasOption()
Returns true if an InputOption object exists by name.
public
hasOption(mixed $name) : bool
Parameters
- $name : mixed
-
The InputOption name
Return values
bool —true if the InputOption object exists, false otherwise
hasParameterOption()
Returns true if the raw parameters (not parsed) contain a value.
public
hasParameterOption(mixed $values[, mixed $onlyParams = false ]) : bool
Parameters
- $values : mixed
-
The values to look for in the raw parameters (can be an array)
- $onlyParams : mixed = false
-
Only check real parameters, skip those following an end of options (--) signal
Return values
bool —true if the value is contained in the raw parameters
isInteractive()
Is this input means interactive?
public
isInteractive() : bool
Return values
boolsetArgument()
Sets an argument value by name.
public
setArgument(mixed $name, mixed $value) : mixed
Parameters
- $name : mixed
-
The argument name
- $value : mixed
-
The argument value
setInteractive()
Sets the input interactivity.
public
setInteractive(mixed $interactive) : mixed
Parameters
- $interactive : mixed
-
If the input should be interactive
setOption()
Sets an option value by name.
public
setOption(mixed $name, mixed $value) : mixed
Parameters
- $name : mixed
-
The option name
- $value : mixed
-
The option value
setStream()
Sets the input stream to read from when interacting with the user.
public
setStream(mixed $stream) : mixed
Parameters
- $stream : mixed
-
The input stream
validate()
Validates the input.
public
validate() : mixed
parse()
Processes command line arguments.
protected
parse() : mixed
setTokens()
protected
setTokens(array<string|int, mixed> $tokens) : mixed
Parameters
- $tokens : array<string|int, mixed>
addLongOption()
Adds a long option value.
private
addLongOption(string $name, mixed $value) : mixed
Parameters
- $name : string
- $value : mixed
Tags
addShortOption()
Adds a short option value.
private
addShortOption(string $shortcut, mixed $value) : mixed
Parameters
- $shortcut : string
- $value : mixed
Tags
parseArgument()
Parses an argument.
private
parseArgument(string $token) : mixed
Parameters
- $token : string
Tags
parseLongOption()
Parses a long option.
private
parseLongOption(string $token) : mixed
Parameters
- $token : string
parseShortOption()
Parses a short option.
private
parseShortOption(string $token) : mixed
Parameters
- $token : string
parseShortOptionSet()
Parses a short option set.
private
parseShortOptionSet(string $name) : mixed
Parameters
- $name : string