function InputDefinition::addOption
Throws
LogicException When option given already exist
1 call to InputDefinition::addOption()
- InputDefinition::addOptions in vendor/
symfony/ console/ Input/ InputDefinition.php - Adds an array of InputOption objects.
File
-
vendor/
symfony/ console/ Input/ InputDefinition.php, line 217
Class
- InputDefinition
- A InputDefinition represents a set of valid command line arguments and options.
Namespace
Symfony\Component\Console\InputCode
public function addOption(InputOption $option) : void {
if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
throw new LogicException(\sprintf('An option named "%s" already exists.', $option->getName()));
}
if (isset($this->negations[$option->getName()])) {
throw new LogicException(\sprintf('An option named "%s" already exists.', $option->getName()));
}
if ($option->getShortcut()) {
foreach (explode('|', $option->getShortcut()) as $shortcut) {
if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
throw new LogicException(\sprintf('An option with shortcut "%s" already exists.', $shortcut));
}
}
}
$this->options[$option->getName()] = $option;
if ($option->getShortcut()) {
foreach (explode('|', $option->getShortcut()) as $shortcut) {
$this->shortcuts[$shortcut] = $option->getName();
}
}
if ($option->isNegatable()) {
$negatedName = 'no-' . $option->getName();
if (isset($this->options[$negatedName])) {
throw new LogicException(\sprintf('An option named "%s" already exists.', $negatedName));
}
$this->negations[$negatedName] = $option->getName();
}
}