Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. InputDefinition.php

function InputDefinition::addArgument

Throws

LogicException When incorrect argument is given

1 call to InputDefinition::addArgument()
InputDefinition::addArguments in vendor/symfony/console/Input/InputDefinition.php
Adds an array of InputArgument objects.

File

vendor/symfony/console/Input/InputDefinition.php, line 97

Class

InputDefinition
A InputDefinition represents a set of valid command line arguments and options.

Namespace

Symfony\Component\Console\Input

Code

public function addArgument(InputArgument $argument) : void {
    if (isset($this->arguments[$argument->getName()])) {
        throw new LogicException(\sprintf('An argument with name "%s" already exists.', $argument->getName()));
    }
    if (null !== $this->lastArrayArgument) {
        throw new LogicException(\sprintf('Cannot add a required argument "%s" after an array argument "%s".', $argument->getName(), $this->lastArrayArgument
            ->getName()));
    }
    if ($argument->isRequired() && null !== $this->lastOptionalArgument) {
        throw new LogicException(\sprintf('Cannot add a required argument "%s" after an optional one "%s".', $argument->getName(), $this->lastOptionalArgument
            ->getName()));
    }
    if ($argument->isArray()) {
        $this->lastArrayArgument = $argument;
    }
    if ($argument->isRequired()) {
        ++$this->requiredCount;
    }
    else {
        $this->lastOptionalArgument = $argument;
    }
    $this->arguments[$argument->getName()] = $argument;
}
RSS feed
Powered by Drupal