12 namespace Symfony\Component\Console\Input;
64 foreach ($definition as $item) {
85 $this->arguments = array();
86 $this->requiredCount = 0;
87 $this->hasOptional =
false;
88 $this->hasAnArrayArgument =
false;
119 if (isset($this->arguments[$argument->
getName()])) {
120 throw new \LogicException(sprintf(
'An argument with name "%s" already exists.', $argument->
getName()));
123 if ($this->hasAnArrayArgument) {
124 throw new \LogicException(
'Cannot add an argument after an array argument.');
128 throw new \LogicException(
'Cannot add a required argument after an optional one.');
132 $this->hasAnArrayArgument =
true;
138 $this->hasOptional =
true;
141 $this->arguments[$argument->
getName()] = $argument;
158 throw new \InvalidArgumentException(sprintf(
'The "%s" argument does not exist.', $name));
201 return $this->hasAnArrayArgument ? PHP_INT_MAX : count($this->arguments);
222 foreach ($this->arguments as $argument) {
223 $values[$argument->getName()] = $argument->getDefault();
238 $this->options = array();
239 $this->shortcuts = array();
268 if (isset($this->options[$option->
getName()]) && !$option->
equals($this->options[$option->
getName()])) {
269 throw new \LogicException(sprintf(
'An option named "%s" already exists.', $option->
getName()));
273 foreach (explode(
'|', $option->
getShortcut()) as $shortcut) {
274 if (isset($this->shortcuts[$shortcut]) && !$option->
equals($this->options[$this->shortcuts[$shortcut]])) {
275 throw new \LogicException(sprintf(
'An option with shortcut "%s" already exists.', $shortcut));
280 $this->options[$option->
getName()] = $option;
282 foreach (explode(
'|', $option->
getShortcut()) as $shortcut) {
283 $this->shortcuts[$shortcut] = $option->
getName();
302 throw new \InvalidArgumentException(sprintf(
'The "--%s" option does not exist.', $name));
305 return $this->options[$name];
319 return isset($this->options[$name]);
343 return isset($this->shortcuts[$name]);
366 foreach ($this->options as $option) {
367 $values[$option->getName()] = $option->getDefault();
384 if (!isset($this->shortcuts[$shortcut])) {
385 throw new \InvalidArgumentException(sprintf(
'The "-%s" option does not exist.', $shortcut));
388 return $this->shortcuts[$shortcut];
403 $elements[] =
'[options]';
407 if ($option->acceptValue()) {
410 $option->isValueOptional() ?
'[' :
'',
411 strtoupper($option->getName()),
412 $option->isValueOptional() ?
']' :
''
416 $shortcut = $option->getShortcut() ? sprintf(
'-%s|', $option->getShortcut()) :
'';
417 $elements[] = sprintf(
'[%s--%s%s]', $shortcut, $option->getName(), $value);
422 $elements[] =
'[--]';
426 $element =
'<'.$argument->getName().
'>';
427 if (!$argument->isRequired()) {
428 $element =
'['.$element.
']';
429 }
elseif ($argument->isArray()) {
430 $element = $element.
' ('.$element.
')';
433 if ($argument->isArray()) {
437 $elements[] = $element;
440 return implode(
' ', $elements);
452 @trigger_error(
'The '.__METHOD__.
' method is deprecated since version 2.3 and will be removed in 3.0.', E_USER_DEPRECATED);
456 $descriptor->describe($output, $this, array(
'raw_output' =>
true));
458 return $output->fetch();
470 public function asXml($asDom =
false)
472 @trigger_error(
'The '.__METHOD__.
' method is deprecated since version 2.3 and will be removed in 3.0.', E_USER_DEPRECATED);
477 return $descriptor->getInputDefinitionDocument($this);
481 $descriptor->describe($output, $this);
483 return $output->fetch();