Class Symfony\Component\Console\Command\Command

InheritanceSymfony\Component\Console\Command\Command
SubclassesSymfony\Component\Console\Command\HelpCommand, Symfony\Component\Console\Command\ListCommand

Base class for all commands.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Constructor. Symfony\Component\Console\Command\Command
addArgument() Adds an argument. Symfony\Component\Console\Command\Command
addOption() Adds an option. Symfony\Component\Console\Command\Command
addUsage() Add a command usage example. Symfony\Component\Console\Command\Command
getAliases() Returns the aliases for the command. Symfony\Component\Console\Command\Command
getApplication() Gets the application instance for this command. Symfony\Component\Console\Command\Command
getDefinition() Gets the InputDefinition attached to this Command. Symfony\Component\Console\Command\Command
getDescription() Returns the description for the command. Symfony\Component\Console\Command\Command
getHelp() Returns the help for the command. Symfony\Component\Console\Command\Command
getHelper() Gets a helper instance by name. Symfony\Component\Console\Command\Command
getHelperSet() Gets the helper set. Symfony\Component\Console\Command\Command
getName() Returns the command name. Symfony\Component\Console\Command\Command
getNativeDefinition() Gets the InputDefinition to be used to create representations of this Command. Symfony\Component\Console\Command\Command
getProcessedHelp() Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically. Symfony\Component\Console\Command\Command
getSynopsis() Returns the synopsis for the command. Symfony\Component\Console\Command\Command
getUsages() Returns alternative usages of the command. Symfony\Component\Console\Command\Command
ignoreValidationErrors() Ignores validation errors. Symfony\Component\Console\Command\Command
isEnabled() Checks whether the command is enabled or not in the current environment. Symfony\Component\Console\Command\Command
mergeApplicationDefinition() Merges the application definition with the command definition. Symfony\Component\Console\Command\Command
run() Runs the command. Symfony\Component\Console\Command\Command
setAliases() Sets the aliases for the command. Symfony\Component\Console\Command\Command
setApplication() Sets the application instance for this command. Symfony\Component\Console\Command\Command
setCode() Sets the code to execute when running this command. Symfony\Component\Console\Command\Command
setDefinition() Sets an array of argument and option instances. Symfony\Component\Console\Command\Command
setDescription() Sets the description for the command. Symfony\Component\Console\Command\Command
setHelp() Sets the help for the command. Symfony\Component\Console\Command\Command
setHelperSet() Sets the helper set. Symfony\Component\Console\Command\Command
setName() Sets the name of the command. Symfony\Component\Console\Command\Command
setProcessTitle() Sets the process title of the command. Symfony\Component\Console\Command\Command

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
configure() Configures the current command. Symfony\Component\Console\Command\Command
execute() Executes the current command. Symfony\Component\Console\Command\Command
initialize() Initializes the command just after the input has been validated. Symfony\Component\Console\Command\Command
interact() Interacts with the user. Symfony\Component\Console\Command\Command

Method Details

__construct() public method

Constructor.

public void __construct ( $name null )
$name string|null

The name of the command; passing null means it must be set in configure()

throws Symfony\Component\Console\Exception\LogicException

When the command name is empty

addArgument() public method

Adds an argument.

public Symfony\Component\Console\Command\Command addArgument ( $name, $mode null, $description '', $default null )
$name string

The argument name

$mode int

The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL

$description string

A description text

$default mixed

The default value (for InputArgument::OPTIONAL mode only)

return Symfony\Component\Console\Command\Command

The current instance

addOption() public method

Adds an option.

public Symfony\Component\Console\Command\Command addOption ( $name, $shortcut null, $mode null, $description '', $default null )
$name string

The option name

$shortcut string

The shortcut (can be null)

$mode int

The option mode: One of the InputOption::VALUE_* constants

$description string

A description text

$default mixed

The default value (must be null for InputOption::VALUE_NONE)

return Symfony\Component\Console\Command\Command

The current instance

addUsage() public method

Add a command usage example.

public void addUsage ( $usage )
$usage string

The usage, it'll be prefixed with the command name

configure() protected method

Configures the current command.

protected void configure ( )
execute() protected method

Executes the current command.

This method is not abstract because you can use this class as a concrete class. In this case, instead of defining the execute() method, you set the code to execute by passing a Closure to the setCode() method.

See also setCode().

protected null|int execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface

An InputInterface instance

$output Symfony\Component\Console\Output\OutputInterface

An OutputInterface instance

return null|int

Null or 0 if everything went fine, or an error code

throws Symfony\Component\Console\Exception\LogicException

When this abstract method is not implemented

getAliases() public method

Returns the aliases for the command.

public array getAliases ( )
return array

An array of aliases for the command

getApplication() public method

Gets the application instance for this command.

public Symfony\Component\Console\Application getApplication ( )
return Symfony\Component\Console\Application

An Application instance

getDefinition() public method

Gets the InputDefinition attached to this Command.

public Symfony\Component\Console\Input\InputDefinition getDefinition ( )
return Symfony\Component\Console\Input\InputDefinition

An InputDefinition instance

getDescription() public method

Returns the description for the command.

public string getDescription ( )
return string

The description for the command

getHelp() public method

Returns the help for the command.

public string getHelp ( )
return string

The help for the command

getHelper() public method

Gets a helper instance by name.

public mixed getHelper ( $name )
$name string

The helper name

return mixed

The helper value

throws Symfony\Component\Console\Exception\LogicException

if no HelperSet is defined

throws Symfony\Component\Console\Exception\InvalidArgumentException

if the helper is not defined

getHelperSet() public method

Gets the helper set.

public Symfony\Component\Console\Helper\HelperSet getHelperSet ( )
return Symfony\Component\Console\Helper\HelperSet

A HelperSet instance

getName() public method

Returns the command name.

public string getName ( )
return string

The command name

getNativeDefinition() public method

Gets the InputDefinition to be used to create representations of this Command.

Can be overridden to provide the original command representation when it would otherwise be changed by merging with the application InputDefinition.

This method is not part of public API and should not be used directly.

public Symfony\Component\Console\Input\InputDefinition getNativeDefinition ( )
return Symfony\Component\Console\Input\InputDefinition

An InputDefinition instance

getProcessedHelp() public method

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

public string getProcessedHelp ( )
return string

The processed help for the command

getSynopsis() public method

Returns the synopsis for the command.

public string getSynopsis ( $short false )
$short bool

Whether to show the short version of the synopsis (with options folded) or not

return string

The synopsis

getUsages() public method

Returns alternative usages of the command.

public array getUsages ( )
ignoreValidationErrors() public method

Ignores validation errors.

This is mainly useful for the help command.

public void ignoreValidationErrors ( )
initialize() protected method

Initializes the command just after the input has been validated.

This is mainly useful when a lot of commands extends one main command where some things need to be initialized based on the input arguments and options.

protected void initialize ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface

An InputInterface instance

$output Symfony\Component\Console\Output\OutputInterface

An OutputInterface instance

interact() protected method

Interacts with the user.

This method is executed before the InputDefinition is validated. This means that this is the only place where the command can interactively ask for values of missing required arguments.

protected void interact ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface

An InputInterface instance

$output Symfony\Component\Console\Output\OutputInterface

An OutputInterface instance

isEnabled() public method

Checks whether the command is enabled or not in the current environment.

Override this to check for x or y and return false if the command can not run properly under the current conditions.

public bool isEnabled ( )
mergeApplicationDefinition() public method

Merges the application definition with the command definition.

This method is not part of public API and should not be used directly.

public void mergeApplicationDefinition ( $mergeArgs true )
$mergeArgs bool

Whether to merge or not the Application definition arguments to Command definition arguments

run() public method

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.

See also:

public int run ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface

An InputInterface instance

$output Symfony\Component\Console\Output\OutputInterface

An OutputInterface instance

return int

The command exit code

throws Exception
setAliases() public method

Sets the aliases for the command.

public Symfony\Component\Console\Command\Command setAliases ( $aliases )
$aliases string[]

An array of aliases for the command

return Symfony\Component\Console\Command\Command

The current instance

throws Symfony\Component\Console\Exception\InvalidArgumentException

When an alias is invalid

setApplication() public method

Sets the application instance for this command.

public void setApplication ( Symfony\Component\Console\Application $application null )
$application Symfony\Component\Console\Application

An Application instance

setCode() public method

Sets the code to execute when running this command.

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

See also execute().

public Symfony\Component\Console\Command\Command setCode ( callable $code )
$code callable

A callable(InputInterface $input, OutputInterface $output)

return Symfony\Component\Console\Command\Command

The current instance

throws Symfony\Component\Console\Exception\InvalidArgumentException
setDefinition() public method

Sets an array of argument and option instances.

public Symfony\Component\Console\Command\Command setDefinition ( $definition )
$definition array|Symfony\Component\Console\Input\InputDefinition

An array of argument and option instances or a definition instance

return Symfony\Component\Console\Command\Command

The current instance

setDescription() public method

Sets the description for the command.

public Symfony\Component\Console\Command\Command setDescription ( $description )
$description string

The description for the command

return Symfony\Component\Console\Command\Command

The current instance

setHelp() public method

Sets the help for the command.

public Symfony\Component\Console\Command\Command setHelp ( $help )
$help string

The help for the command

return Symfony\Component\Console\Command\Command

The current instance

setHelperSet() public method

Sets the helper set.

public void setHelperSet ( Symfony\Component\Console\Helper\HelperSet $helperSet )
$helperSet Symfony\Component\Console\Helper\HelperSet

A HelperSet instance

setName() public method

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');
public Symfony\Component\Console\Command\Command setName ( $name )
$name string

The command name

return Symfony\Component\Console\Command\Command

The current instance

throws Symfony\Component\Console\Exception\InvalidArgumentException

When the name is invalid

setProcessTitle() public method

Sets the process title of the command.

This feature should be used only when creating a long process command, like a daemon.

PHP 5.5+ or the proctitle PECL library is required

public Symfony\Component\Console\Command\Command setProcessTitle ( $title )
$title string

The process title

return Symfony\Component\Console\Command\Command

The current instance