class InputOption
Same name in this branch
- 11.1.x vendor/symfony/console/Input/InputOption.php \Symfony\Component\Console\Input\InputOption
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\InputOption
- class \Composer\Console\Input\InputOption extends \Symfony\Component\Console\Input\InputOption
Expanded class hierarchy of InputOption
26 files declare their use of InputOption
- ArchiveCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ ArchiveCommand.php - AuditCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ AuditCommand.php - BaseCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ BaseCommand.php - BumpCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ BumpCommand.php - CheckPlatformReqsCommand.php in vendor/
composer/ composer/ src/ Composer/ Command/ CheckPlatformReqsCommand.php
File
-
vendor/
composer/ composer/ src/ Composer/ Console/ Input/ InputOption.php, line 31
Namespace
Composer\Console\InputView source
class InputOption extends BaseInputOption {
/**
* @var list<string>|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion>
*/
private $suggestedValues;
/**
* @param string|string[]|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the VALUE_* constants
* @param string|bool|int|float|string[]|null $default The default value (must be null for self::VALUE_NONE)
* @param list<string>|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion> $suggestedValues The values used for input completionnull for self::VALUE_NONE)
*
* @throws InvalidArgumentException If option mode is invalid or incompatible
*/
public function __construct(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null, $suggestedValues = []) {
parent::__construct($name, $shortcut, $mode, $description, $default);
$this->suggestedValues = $suggestedValues;
if ([] !== $suggestedValues && !$this->acceptValue()) {
throw new LogicException('Cannot set suggested values if the option does not accept a value.');
}
}
/**
* 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 argument "%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 |
---|---|---|---|---|
InputOption::$default | private | property | ||
InputOption::$mode | private | property | ||
InputOption::$name | private | property | ||
InputOption::$shortcut | private | property | ||
InputOption::$suggestedValues | private | property | ||
InputOption::acceptValue | public | function | Returns true if the option accepts a value. | |
InputOption::complete | public | function | Adds suggestions to $suggestions for the current completion input. | Overrides InputOption::complete |
InputOption::equals | public | function | Checks whether the given option equals this one. | |
InputOption::getDefault | public | function | Returns the default value. | |
InputOption::getDescription | public | function | Returns the description text. | |
InputOption::getName | public | function | Returns the option name. | |
InputOption::getShortcut | public | function | Returns the option shortcut. | |
InputOption::hasCompletion | public | function | Returns true if the option has values for input completion. | |
InputOption::isArray | public | function | Returns true if the option can take multiple values. | |
InputOption::isNegatable | public | function | Returns true if the option allows passing a negated variant. | |
InputOption::isValueOptional | public | function | Returns true if the option takes an optional value. | |
InputOption::isValueRequired | public | function | Returns true if the option requires a value. | |
InputOption::setDefault | public | function | Sets the default value. | |
InputOption::VALUE_IS_ARRAY | public | constant | The option accepts multiple values (e.g. --dir=/foo --dir=/bar). | |
InputOption::VALUE_NEGATABLE | public | constant | The option allows passing a negated variant (e.g. --ansi or --no-ansi). | |
InputOption::VALUE_NONE | public | constant | Do not accept input for the option (e.g. --yell). This is the default behavior of options. | |
InputOption::VALUE_OPTIONAL | public | constant | The option may or may not have a value (e.g. --yell or --yell=loud). | |
InputOption::VALUE_REQUIRED | public | constant | A value must be passed when the option is used (e.g. --iterations=5 or -i5). | |
InputOption::__construct | public | function | Overrides InputOption::__construct |