function InputOption::__construct
Same name in this branch
- 11.1.x vendor/composer/composer/src/Composer/Console/Input/InputOption.php \Composer\Console\Input\InputOption::__construct()
Parameters
string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts:
int-mask-of<InputOption::*>|null $mode The option mode: One of the VALUE_* constants:
string|bool|int|float|array|null $default The default value (must be null for self::VALUE_NONE):
array|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion> $suggestedValues The values used for input completion:
Throws
InvalidArgumentException If option mode is invalid or incompatible
2 calls to InputOption::__construct()
- InputOption::__construct in vendor/
composer/ composer/ src/ Composer/ Console/ Input/ InputOption.php - InputOption::__construct in vendor/
composer/ composer/ src/ Composer/ Console/ Input/ InputOption.php
1 method overrides InputOption::__construct()
- InputOption::__construct in vendor/
composer/ composer/ src/ Composer/ Console/ Input/ InputOption.php
File
-
vendor/
symfony/ console/ Input/ InputOption.php, line 66
Class
- InputOption
- Represents a command line option.
Namespace
Symfony\Component\Console\InputCode
public function __construct(string $name, string|array|null $shortcut = null, ?int $mode = null, string $description = '', string|bool|int|float|array|null $default = null, array|\Closure $suggestedValues = []) {
if (str_starts_with($name, '--')) {
$name = substr($name, 2);
}
if (!$name) {
throw new InvalidArgumentException('An option name cannot be empty.');
}
if ('' === $shortcut || [] === $shortcut || false === $shortcut) {
$shortcut = null;
}
if (null !== $shortcut) {
if (\is_array($shortcut)) {
$shortcut = implode('|', $shortcut);
}
$shortcuts = preg_split('{(\\|)-?}', ltrim($shortcut, '-'));
$shortcuts = array_filter($shortcuts, 'strlen');
$shortcut = implode('|', $shortcuts);
if ('' === $shortcut) {
throw new InvalidArgumentException('An option shortcut cannot be empty.');
}
}
if (null === $mode) {
$mode = self::VALUE_NONE;
}
elseif ($mode >= self::VALUE_NEGATABLE << 1 || $mode < 1) {
throw new InvalidArgumentException(\sprintf('Option mode "%s" is not valid.', $mode));
}
$this->name = $name;
$this->shortcut = $shortcut;
$this->mode = $mode;
if ($suggestedValues && !$this->acceptValue()) {
throw new LogicException('Cannot set suggested values if the option does not accept a value.');
}
if ($this->isArray() && !$this->acceptValue()) {
throw new InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
}
if ($this->isNegatable() && $this->acceptValue()) {
throw new InvalidArgumentException('Impossible to have an option mode VALUE_NEGATABLE if the option also accepts a value.');
}
$this->setDefault($default);
}