class InputArgument
Same name in this branch
- 11.1.x vendor/symfony/console/Input/InputArgument.php \Symfony\Component\Console\Input\InputArgument
Backport suggested values definition from symfony/console 6.1+
@author Jérôme Tamarelle <jerome@tamarelle.net>
@internal
TODO symfony/console:6.1 drop when PHP 8.1 / symfony 6.1+ can be required
Hierarchy
- class \Symfony\Component\Console\Input\InputArgument
- class \Composer\Console\Input\InputArgument extends \Symfony\Component\Console\Input\InputArgument
Expanded class hierarchy of InputArgument
22 files declare their use of InputArgument
- ArchiveCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ ArchiveCommand.php - BaseCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ BaseCommand.php - BumpCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ BumpCommand.php - ConfigCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ ConfigCommand.php - CreateProjectCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ CreateProjectCommand.php
File
-
vendor/
composer/ composer/ src/ Composer/ Console/ Input/ InputArgument.php, line 31
Namespace
Composer\Console\InputView source
class InputArgument extends BaseInputArgument {
/**
* @var list<string>|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion>
*/
private $suggestedValues;
/**
* @param string $name The argument name
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
* @param string $description A description text
* @param string|bool|int|float|string[]|null $default The default value (for self::OPTIONAL mode only)
* @param list<string>|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion> $suggestedValues The values used for input completion
*
* @throws InvalidArgumentException When argument mode is not valid
*/
public function __construct(string $name, ?int $mode = null, string $description = '', $default = null, $suggestedValues = []) {
parent::__construct($name, $mode, $description, $default);
$this->suggestedValues = $suggestedValues;
}
/**
* Adds suggestions to $suggestions for the current completion input.
*
* @see Command::complete()
*/
public function complete(CompletionInput $input, CompletionSuggestions $suggestions) : void {
$values = $this->suggestedValues;
if ($values instanceof \Closure && !\is_array($values = $values($input, $suggestions))) {
// @phpstan-ignore function.impossibleType
throw new LogicException(sprintf('Closure for option "%s" must return an array. Got "%s".', $this->getName(), get_debug_type($values)));
}
if ([] !== $values) {
$suggestions->suggestValues($values);
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
InputArgument::$default | private | property | ||
InputArgument::$mode | private | property | ||
InputArgument::$suggestedValues | private | property | ||
InputArgument::complete | public | function | Adds suggestions to $suggestions for the current completion input. | Overrides InputArgument::complete |
InputArgument::getDefault | public | function | Returns the default value. | |
InputArgument::getDescription | public | function | Returns the description text. | |
InputArgument::getName | public | function | Returns the argument name. | |
InputArgument::hasCompletion | public | function | Returns true if the argument has values for input completion. | |
InputArgument::isArray | public | function | Returns true if the argument can take multiple values. | |
InputArgument::isRequired | public | function | Returns true if the argument is required. | |
InputArgument::IS_ARRAY | public | constant | The argument accepts multiple values and turn them into an array (e.g. 'app:foo bar baz' will result in value ['bar', 'baz']). | |
InputArgument::OPTIONAL | public | constant | Providing an argument is optional (e.g. 'app:foo' and 'app:foo bar' are both allowed). This is the default behavior of arguments. | |
InputArgument::REQUIRED | public | constant | Providing an argument is required (e.g. just 'app:foo' is not allowed). | |
InputArgument::setDefault | public | function | Sets the default value. | |
InputArgument::__construct | public | function | Overrides InputArgument::__construct |