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

Constructor.

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)

Adds an InputArgument object.

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)

Adds an InputOption object.

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 43
__construct(array $definition = array())

Constructor.

Parameters

array $definition An array of InputArgument and InputOption instance

at line line 53
setDefinition(array $definition)

Sets the definition of the input.

Parameters

array $definition The definition array

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

Sets the InputArgument objects.

Parameters

InputArgument[] $arguments An array of InputArgument objects

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

Adds an array of InputArgument objects.

Parameters

InputArgument[] $arguments An array of InputArgument objects

at line line 104
addArgument(InputArgument $argument)

Adds an InputArgument object.

Parameters

InputArgument $argument An InputArgument object

Exceptions

LogicException When incorrect argument is given

at line line 140
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 158
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 170
InputArgument[] getArguments()

Gets the array of InputArgument objects.

Return Value

InputArgument[] An array of InputArgument objects

at line line 180
int getArgumentCount()

Returns the number of InputArguments.

Return Value

int The number of InputArguments

at line line 190
int getArgumentRequiredCount()

Returns the number of required InputArguments.

Return Value

int The number of required InputArguments

at line line 200
array getArgumentDefaults()

Gets the default values.

Return Value

array An array of default values

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

Sets the InputOption objects.

Parameters

InputOption[] $options An array of InputOption objects

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

Adds an array of InputOption objects.

Parameters

InputOption[] $options An array of InputOption objects

at line line 241
addOption(InputOption $option)

Adds an InputOption object.

Parameters

InputOption $option An InputOption object

Exceptions

LogicException When option given already exist

at line line 272
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 288
bool hasOption(string $name)

Returns true if an InputOption object exists by name.

Parameters

string $name The InputOption name

Return Value

bool true if the InputOption object exists, false otherwise

at line line 298
InputOption[] getOptions()

Gets the array of InputOption objects.

Return Value

InputOption[] An array of InputOption objects

at line line 310
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 322
InputOption getOptionForShortcut(string $shortcut)

Gets an InputOption by shortcut.

Parameters

string $shortcut the Shortcut name

Return Value

InputOption An InputOption object

at line line 332
array getOptionDefaults()

Gets an array of default values.

Return Value

array An array of all default values

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