public function InputOption::__construct in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/console/Input/InputOption.php \Symfony\Component\Console\Input\InputOption::__construct()
Constructor.
Parameters
string $name The option name:
string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts:
int $mode The option mode: One of the VALUE_* constants:
string $description A description text:
mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE):
Throws
\InvalidArgumentException If option mode is invalid or incompatible
File
- vendor/
symfony/ console/ Input/ InputOption.php, line 43
Class
- InputOption
- Represents a command line option.
Namespace
Symfony\Component\Console\InputCode
public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null) {
if (0 === strpos($name, '--')) {
$name = substr($name, 2);
}
if (empty($name)) {
throw new \InvalidArgumentException('An option name cannot be empty.');
}
if (empty($shortcut)) {
$shortcut = null;
}
if (null !== $shortcut) {
if (is_array($shortcut)) {
$shortcut = implode('|', $shortcut);
}
$shortcuts = preg_split('{(\\|)-?}', ltrim($shortcut, '-'));
$shortcuts = array_filter($shortcuts);
$shortcut = implode('|', $shortcuts);
if (empty($shortcut)) {
throw new \InvalidArgumentException('An option shortcut cannot be empty.');
}
}
if (null === $mode) {
$mode = self::VALUE_NONE;
}
elseif (!is_int($mode) || $mode > 15 || $mode < 1) {
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
}
$this->name = $name;
$this->shortcut = $shortcut;
$this->mode = $mode;
$this->description = $description;
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.');
}
$this
->setDefault($default);
}