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())

No description

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)

No description

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.

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)

No description

getOption(string $name)

Returns an InputOption by name.

bool
hasOption(string $name)

Returns true if an InputOption object exists by name.

getOptions()

Gets the array of InputOption objects.

bool
hasShortcut(string $name)

Returns true if an InputOption object exists by shortcut.

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

at line line 41
__construct(array $definition = array())

Parameters

array $definition An array of InputArgument and InputOption instance

at line line 49
setDefinition(array $definition)

Sets the definition of the input.

Parameters

array $definition

at line line 70
setArguments(InputArgument[] $arguments = array())

Sets the InputArgument objects.

Parameters

InputArgument[] $arguments An array of InputArgument objects

at line line 84
addArguments(InputArgument[] $arguments = array())

Adds an array of InputArgument objects.

Parameters

InputArgument[] $arguments An array of InputArgument objects

at line line 96
addArgument(InputArgument $argument)

Parameters

InputArgument $argument

Exceptions

LogicException When incorrect argument is given

at line line 132
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

at line line 150
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

at line line 162
InputArgument[] getArguments()

Gets the array of InputArgument objects.

Return Value

InputArgument[] An array of InputArgument objects

at line line 172
int getArgumentCount()

Returns the number of InputArguments.

Return Value

int The number of InputArguments

at line line 182
int getArgumentRequiredCount()

Returns the number of required InputArguments.

Return Value

int The number of required InputArguments

at line line 192
array getArgumentDefaults()

Gets the default values.

Return Value

array An array of default values

at line line 207
setOptions(InputOption[] $options = array())

Sets the InputOption objects.

Parameters

InputOption[] $options An array of InputOption objects

at line line 219
addOptions(InputOption[] $options = array())

Adds an array of InputOption objects.

Parameters

InputOption[] $options An array of InputOption objects

at line line 229
addOption(InputOption $option)

Parameters

InputOption $option

Exceptions

LogicException When option given already exist

at line line 260
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

at line line 279
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

at line line 289
InputOption[] getOptions()

Gets the array of InputOption objects.

Return Value

InputOption[] An array of InputOption objects

at line line 301
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

at line line 313
InputOption getOptionForShortcut(string $shortcut)

Gets an InputOption by shortcut.

Parameters

string $shortcut The Shortcut name

Return Value

InputOption An InputOption object

at line line 323
array getOptionDefaults()

Gets an array of default values.

Return Value

array An array of all default values

at line line 358
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