InputDefinition

class InputDefinition

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

Usage:

$definition = new InputDefinition(array(
  new InputArgument('name', InputArgument::REQUIRED),
  new InputOption('foo', 'f', InputOption::VALUE_REQUIRED),
));

Methods

__construct(array $definition = array())
setDefinition(array $definition)

Sets the definition of the input.

setArguments(InputArgument[] $arguments = array())

Sets the InputArgument objects.

addArguments(InputArgument[] $arguments = array())

Adds an array of InputArgument objects.

addArgument(InputArgument $argument)
InputArgument getArgument(string|int $name)

Returns an InputArgument by name or by position.

bool hasArgument(string|int $name)

Returns true if an InputArgument object exists by name or position.

InputArgument[] getArguments()

Gets the array of InputArgument objects.

int getArgumentCount()

Returns the number of InputArguments.

int getArgumentRequiredCount()

Returns the number of required InputArguments.

array getArgumentDefaults()

Gets the default values.

setOptions(InputOption[] $options = array())

Sets the InputOption objects.

addOptions(InputOption[] $options = array())

Adds an array of InputOption objects.

addOption(InputOption $option)
InputOption getOption(string $name)

Returns an InputOption by name.

bool hasOption(string $name)

Returns true if an InputOption object exists by name.

InputOption[] getOptions()

Gets the array of InputOption objects.

bool hasShortcut(string $name)

Returns true if an InputOption object exists by shortcut.

InputOption getOptionForShortcut(string $shortcut)

Gets an InputOption by shortcut.

array getOptionDefaults()

Gets an array of default values.

string getSynopsis(bool $short = false)

Gets the synopsis.

Details

__construct(array $definition = array())

Parameters

array $definition An array of InputArgument and InputOption instance

setDefinition(array $definition)

Sets the definition of the input.

Parameters

array $definition

setArguments(InputArgument[] $arguments = array())

Sets the InputArgument objects.

Parameters

InputArgument[] $arguments An array of InputArgument objects

addArguments(InputArgument[] $arguments = array())

Adds an array of InputArgument objects.

Parameters

InputArgument[] $arguments An array of InputArgument objects

addArgument(InputArgument $argument)

Parameters

InputArgument $argument

Exceptions

LogicException When incorrect argument is given

InputArgument getArgument(string|int $name)

Returns an InputArgument by name or by position.

Parameters

string|int $name The InputArgument name or position

Return Value

InputArgument An InputArgument object

Exceptions

InvalidArgumentException When argument given doesn't exist

bool hasArgument(string|int $name)

Returns true if an InputArgument object exists by name or position.

Parameters

string|int $name The InputArgument name or position

Return Value

bool true if the InputArgument object exists, false otherwise

InputArgument[] getArguments()

Gets the array of InputArgument objects.

Return Value

InputArgument[] An array of InputArgument objects

int getArgumentCount()

Returns the number of InputArguments.

Return Value

int The number of InputArguments

int getArgumentRequiredCount()

Returns the number of required InputArguments.

Return Value

int The number of required InputArguments

array getArgumentDefaults()

Gets the default values.

Return Value

array An array of default values

setOptions(InputOption[] $options = array())

Sets the InputOption objects.

Parameters

InputOption[] $options An array of InputOption objects

addOptions(InputOption[] $options = array())

Adds an array of InputOption objects.

Parameters

InputOption[] $options An array of InputOption objects

addOption(InputOption $option)

Parameters

InputOption $option

Exceptions

LogicException When option given already exist

InputOption getOption(string $name)

Returns an InputOption by name.

Parameters

string $name The InputOption name

Return Value

InputOption A InputOption object

Exceptions

InvalidArgumentException When option given doesn't exist

bool hasOption(string $name)

Returns true if an InputOption object exists by name.

This method can't be used to check if the user included the option when executing the command (use getOption() instead).

Parameters

string $name The InputOption name

Return Value

bool true if the InputOption object exists, false otherwise

InputOption[] getOptions()

Gets the array of InputOption objects.

Return Value

InputOption[] An array of InputOption objects

bool hasShortcut(string $name)

Returns true if an InputOption object exists by shortcut.

Parameters

string $name The InputOption shortcut

Return Value

bool true if the InputOption object exists, false otherwise

InputOption getOptionForShortcut(string $shortcut)

Gets an InputOption by shortcut.

Parameters

string $shortcut The Shortcut name

Return Value

InputOption An InputOption object

array getOptionDefaults()

Gets an array of default values.

Return Value

array An array of all default values

string getSynopsis(bool $short = false)

Gets the synopsis.

Parameters

bool $short Whether to return the short version (with options folded) or not

Return Value

string The synopsis

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/4.0/Symfony/Component/Console/Input/InputDefinition.html