CompletionInput
extends ArgvInput
in package
An input specialized for shell completion.
This input allows unfinished option names or values and exposes what kind of completion is expected.
Tags
Table of Contents
Constants
- TYPE_ARGUMENT_VALUE = 'argument_value'
- TYPE_NONE = 'none'
- TYPE_OPTION_NAME = 'option_name'
- TYPE_OPTION_VALUE = 'option_value'
Properties
- $arguments : mixed
- $definition : mixed
- $interactive : mixed
- $options : mixed
- $stream : mixed
- $completionName : mixed
- $completionType : mixed
- $completionValue : mixed
- $currentIndex : mixed
- $parsed : mixed
- $tokens : mixed
Methods
- __construct() : mixed
- __toString() : string
- Returns a stringified representation of the args passed to the command.
- bind() : void
- Binds the current Input instance with the given arguments and options.
- escapeToken() : string
- Escapes a token through escapeshellarg if it contains unsafe chars.
- fromString() : self
- Converts a terminal string into tokens.
- fromTokens() : self
- Create an input based on an COMP_WORDS token list.
- 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.
- getCompletionName() : string|null
- The name of the input option or argument when completing a value.
- getCompletionType() : string
- Returns the type of completion required.
- getCompletionValue() : string
- The value already typed by the user (or empty string).
- 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?
- mustSuggestArgumentValuesFor() : bool
- mustSuggestOptionValuesFor() : bool
- 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.
- parseToken() : bool
- setTokens() : mixed
- addLongOption() : mixed
- Adds a long option value.
- addShortOption() : mixed
- Adds a short option value.
- getOptionFromToken() : InputOption|null
- getRelevantToken() : string
- The token of the cursor, or the last token if the cursor is at the end of the input.
- isCursorFree() : bool
- Whether the cursor is "free" (i.e. at the end of the input preceded by a space).
- parseArgument() : mixed
- Parses an argument.
- parseLongOption() : mixed
- Parses a long option.
- parseShortOption() : mixed
- Parses a short option.
- parseShortOptionSet() : mixed
- Parses a short option set.
Constants
TYPE_ARGUMENT_VALUE
public
mixed
TYPE_ARGUMENT_VALUE
= 'argument_value'
TYPE_NONE
public
mixed
TYPE_NONE
= 'none'
TYPE_OPTION_NAME
public
mixed
TYPE_OPTION_NAME
= 'option_name'
TYPE_OPTION_VALUE
public
mixed
TYPE_OPTION_VALUE
= 'option_value'
Properties
$arguments
protected
mixed
$arguments
= []
$definition
protected
mixed
$definition
$interactive
protected
mixed
$interactive
= true
$options
protected
mixed
$options
= []
$stream
protected
mixed
$stream
$completionName
private
mixed
$completionName
= null
$completionType
private
mixed
$completionType
$completionValue
private
mixed
$completionValue
= ''
$currentIndex
private
mixed
$currentIndex
$parsed
private
mixed
$parsed
$tokens
private
mixed
$tokens
Methods
__construct()
public
__construct([array<string|int, mixed>|null $argv = null ][, InputDefinition|null $definition = null ]) : mixed
Parameters
- $argv : array<string|int, mixed>|null = null
- $definition : InputDefinition|null = 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) : void
Parameters
- $definition : InputDefinition
escapeToken()
Escapes a token through escapeshellarg if it contains unsafe chars.
public
escapeToken(string $token) : string
Parameters
- $token : string
Return values
stringfromString()
Converts a terminal string into tokens.
public
static fromString(string $inputStr, int $currentIndex) : self
This is required for shell completions without COMP_WORDS support.
Parameters
- $inputStr : string
- $currentIndex : int
Return values
selffromTokens()
Create an input based on an COMP_WORDS token list.
public
static fromTokens(array<string|int, string> $tokens, mixed $currentIndex) : self
Parameters
- $tokens : array<string|int, string>
-
the set of split tokens (e.g. COMP_WORDS or argv)
- $currentIndex : mixed
-
the index of the cursor (e.g. COMP_CWORD)
Return values
selfgetArgument()
Returns the argument value for a given argument name.
public
getArgument(string $name) : mixed
Parameters
- $name : string
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>getCompletionName()
The name of the input option or argument when completing a value.
public
getCompletionName() : string|null
Return values
string|null —returns null when completing an option name
getCompletionType()
Returns the type of completion required.
public
getCompletionType() : string
TYPE_ARGUMENT_VALUE when completing the value of an input argument TYPE_OPTION_VALUE when completing the value of an input option TYPE_OPTION_NAME when completing the name of an input option TYPE_NONE when nothing should be completed
Return values
string —One of self::TYPE_* constants. TYPE_OPTION_NAME and TYPE_NONE are already implemented by the Console component
getCompletionValue()
The value already typed by the user (or empty string).
public
getCompletionValue() : string
Return values
stringgetFirstArgument()
Returns the first argument from the raw parameters (not parsed).
public
getFirstArgument() : string|null
Return values
string|nullgetOption()
Returns the option value for a given option name.
public
getOption(string $name) : mixed
Parameters
- $name : string
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 ][, bool $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 : bool = false
-
Only check real parameters, skip those following an end of options (--) signal
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(string $name) : bool
Parameters
- $name : string
Return values
boolhasOption()
Returns true if an InputOption object exists by name.
public
hasOption(string $name) : bool
Parameters
- $name : string
Return values
boolhasParameterOption()
Returns true if the raw parameters (not parsed) contain a value.
public
hasParameterOption(mixed $values[, bool $onlyParams = false ]) : bool
Parameters
- $values : mixed
-
The values to look for in the raw parameters (can be an array)
- $onlyParams : bool = false
-
Only check real parameters, skip those following an end of options (--) signal
Return values
boolisInteractive()
Is this input means interactive?
public
isInteractive() : bool
Return values
boolmustSuggestArgumentValuesFor()
public
mustSuggestArgumentValuesFor(string $argumentName) : bool
Parameters
- $argumentName : string
Return values
boolmustSuggestOptionValuesFor()
public
mustSuggestOptionValuesFor(string $optionName) : bool
Parameters
- $optionName : string
Return values
boolsetArgument()
Sets an argument value by name.
public
setArgument(string $name, mixed $value) : mixed
Parameters
- $name : string
- $value : mixed
-
The argument value
setInteractive()
Sets the input interactivity.
public
setInteractive(bool $interactive) : mixed
Parameters
- $interactive : bool
setOption()
Sets an option value by name.
public
setOption(string $name, mixed $value) : mixed
Parameters
- $name : string
- $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
parseToken()
protected
parseToken(string $token, bool $parseOptions) : bool
Parameters
- $token : string
- $parseOptions : bool
Return values
boolsetTokens()
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
getOptionFromToken()
private
getOptionFromToken(string $optionToken) : InputOption|null
Parameters
- $optionToken : string
Return values
InputOption|nullgetRelevantToken()
The token of the cursor, or the last token if the cursor is at the end of the input.
private
getRelevantToken() : string
Return values
stringisCursorFree()
Whether the cursor is "free" (i.e. at the end of the input preceded by a space).
private
isCursorFree() : bool
Return values
boolparseArgument()
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