Class

Symfony\Component\Console\Command\Command

class Command

Base class for all commands.

Methods

__construct(string $name = null)

Constructor.

ignoreValidationErrors()

Ignores validation errors.

setApplication(Application $application = null)

Sets the application instance for this command.

setHelperSet(HelperSet $helperSet)

Sets the helper set.

HelperSet getHelperSet()

Gets the helper set.

Application getApplication()

Gets the application instance for this command.

integer run(InputInterface $input, OutputInterface $output)

Runs the command.

Command setCode(Closure $code)

Sets the code to execute when running this command.

Command setDefinition(array|InputDefinition $definition)

Sets an array of argument and option instances.

InputDefinition getDefinition()

Gets the InputDefinition attached to this Command.

Command addArgument(string $name, integer $mode = null, string $description = '', mixed $default = null)

Adds an argument.

Command addOption(string $name, string $shortcut = null, integer $mode = null, string $description = '', mixed $default = null)

Adds an option.

Command setName(string $name)

Sets the name of the command.

string getName()

Returns the command name.

Command setDescription(string $description)

Sets the description for the command.

string getDescription()

Returns the description for the command.

Command setHelp(string $help)

Sets the help for the command.

string getHelp()

Returns the help for the command.

string getProcessedHelp()

Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.

Command setAliases(array $aliases)

Sets the aliases for the command.

array getAliases()

Returns the aliases for the command.

string getSynopsis()

Returns the synopsis for the command.

mixed getHelper(string $name)

Gets a helper instance by name.

string asText()

Returns a text representation of the command.

string|DOMDocument asXml(Boolean $asDom = false)

Returns an XML representation of the command.

Details

at line 52
public __construct(string $name = null)

Constructor.

Parameters

string $name The name of the command

Exceptions

LogicException When the command name is empty

at line 75
public ignoreValidationErrors()

Ignores validation errors.

This is mainly useful for the help command.

at line 87
public setApplication(Application $application = null)

Sets the application instance for this command.

Parameters

Application $application An Application instance

at line 102
public setHelperSet(HelperSet $helperSet)

Sets the helper set.

Parameters

HelperSet $helperSet A HelperSet instance

at line 112
public HelperSet getHelperSet()

Gets the helper set.

Return Value

HelperSet A HelperSet instance

at line 124
public Application getApplication()

Gets the application instance for this command.

Return Value

Application An Application instance

at line 197
public integer run(InputInterface $input, OutputInterface $output)

Runs the command.

The code to execute is either defined directly with the setCode() method or by overriding the execute() method in a sub-class.

Parameters

InputInterface $input An InputInterface instance
OutputInterface $output An OutputInterface instance

Return Value

integer The command exit code

See also

setCode()
execute()

at line 243
public Command setCode(Closure $code)

Sets the code to execute when running this command.

If this method is used, it overrides the code defined in the execute() method.

Parameters

Closure $code A \Closure

Return Value

Command The current instance

See also

execute()

at line 278
public Command setDefinition(array|InputDefinition $definition)

Sets an array of argument and option instances.

Parameters

array|InputDefinition $definition An array of argument and option instances or a definition instance

Return Value

Command The current instance

at line 298
public InputDefinition getDefinition()

Gets the InputDefinition attached to this Command.

Return Value

InputDefinition An InputDefinition instance

at line 328
public Command addArgument(string $name, integer $mode = null, string $description = '', mixed $default = null)

Adds an argument.

Parameters

string $name The argument name
integer $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
string $description A description text
mixed $default The default value (for InputArgument::OPTIONAL mode only)

Return Value

Command The current instance

at line 348
public Command addOption(string $name, string $shortcut = null, integer $mode = null, string $description = '', mixed $default = null)

Adds an option.

Parameters

string $name The option name
string $shortcut The shortcut (can be null)
integer $mode The option mode: One of the InputOption::VALUE_* constants
string $description A description text
mixed $default The default value (must be null for InputOption::VALUEREQUIRED or InputOption::VALUENONE)

Return Value

Command The current instance

at line 371
public Command setName(string $name)

Sets the name of the command.

This method can set both the namespace and the name if you separate them by a colon (:)

$command->setName('foo:bar');

Parameters

string $name The command name

Return Value

Command The current instance

Exceptions

InvalidArgumentException When command name given is empty

at line 387
public string getName()

Returns the command name.

Return Value

string The command name

at line 401
public Command setDescription(string $description)

Sets the description for the command.

Parameters

string $description The description for the command

Return Value

Command The current instance

at line 415
public string getDescription()

Returns the description for the command.

Return Value

string The description for the command

at line 429
public Command setHelp(string $help)

Sets the help for the command.

Parameters

string $help The help for the command

Return Value

Command The current instance

at line 443
public string getHelp()

Returns the help for the command.

Return Value

string The help for the command

at line 454
public string getProcessedHelp()

Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.

Return Value

string The processed help for the command

at line 479
public Command setAliases(array $aliases)

Sets the aliases for the command.

Parameters

array $aliases An array of aliases for the command

Return Value

Command The current instance

at line 497
public array getAliases()

Returns the aliases for the command.

Return Value

array An array of aliases for the command

at line 507
public string getSynopsis()

Returns the synopsis for the command.

Return Value

string The synopsis

at line 527
public mixed getHelper(string $name)

Gets a helper instance by name.

Parameters

string $name The helper name

Return Value

mixed The helper value

Exceptions

InvalidArgumentException if the helper is not defined

at line 537
public string asText()

Returns a text representation of the command.

Return Value

string A string representing the command

at line 566
public string|DOMDocument asXml(Boolean $asDom = false)

Returns an XML representation of the command.

Parameters

Boolean $asDom Whether to return a DOM or an XML string

Return Value

string|DOMDocument An XML string representing the command