PHP Class Symfony\Component\Console\Command\Command

Afficher le fichier Open project: symfony/symfony Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( string | null $name = null ) Constructor.
addArgument ( string $name, integer $mode = null, string $description = '', mixed $default = null ) : Command Adds an argument.
addOption ( string $name, string $shortcut = null, integer $mode = null, string $description = '', mixed $default = null ) : Command Adds an option.
addUsage ( string $usage ) : Command Add a command usage example.
getAliases ( ) : array Returns the aliases for the command.
getApplication ( ) : Application Gets the application instance for this command.
getDefinition ( ) : Symfony\Component\Console\Input\InputDefinition Gets the InputDefinition attached to this Command.
getDescription ( ) : string Returns the description for the command.
getHelp ( ) : string Returns the help for the command.
getHelper ( string $name ) : mixed Gets a helper instance by name.
getHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet Gets the helper set.
getName ( ) : string Returns the command name.
getNativeDefinition ( ) : Symfony\Component\Console\Input\InputDefinition Gets the InputDefinition to be used to create representations of this Command.
getProcessedHelp ( ) : string Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.
getSynopsis ( boolean $short = false ) : string Returns the synopsis for the command.
getUsages ( ) : array Returns alternative usages of the command.
ignoreValidationErrors ( ) Ignores validation errors.
isEnabled ( ) : boolean Checks whether the command is enabled or not in the current environment.
isHidden ( ) : boolean
mergeApplicationDefinition ( boolean $mergeArgs = true ) Merges the application definition with the command definition.
run ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer Runs the command.
setAliases ( string[] $aliases ) : Command Sets the aliases for the command.
setApplication ( Application $application = null ) Sets the application instance for this command.
setCode ( callable $code ) : Command Sets the code to execute when running this command.
setDefinition ( array | Symfony\Component\Console\Input\InputDefinition $definition ) : Command Sets an array of argument and option instances.
setDescription ( string $description ) : Command Sets the description for the command.
setHelp ( string $help ) : Command Sets the help for the command.
setHelperSet ( Symfony\Component\Console\Helper\HelperSet $helperSet ) Sets the helper set.
setHidden ( boolean $hidden ) : Command
setName ( string $name ) : Command Sets the name of the command.
setProcessTitle ( string $title ) : Command Sets the process title of the command.

Méthodes protégées

Méthode Description
configure ( ) Configures the current command.
execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : null | integer Executes the current command.
initialize ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) Initializes the command just after the input has been validated.
interact ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) Interacts with the user.

Private Methods

Méthode Description
validateName ( string $name ) Validates a command name.

Method Details

__construct() public méthode

Constructor.
public __construct ( string | null $name = null )
$name string | null The name of the command; passing null means it must be set in configure()

addArgument() public méthode

Adds an argument.
public addArgument ( string $name, integer $mode = null, string $description = '', mixed $default = null ) : Command
$name string The argument name
$mode integer The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
$description string A description text
$default mixed The default value (for InputArgument::OPTIONAL mode only)
Résultat Command The current instance

addOption() public méthode

Adds an option.
public addOption ( string $name, string $shortcut = null, integer $mode = null, string $description = '', mixed $default = null ) : Command
$name string The option name
$shortcut string The shortcut (can be null)
$mode integer 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)
Résultat Command The current instance

addUsage() public méthode

Add a command usage example.
public addUsage ( string $usage ) : Command
$usage string The usage, it'll be prefixed with the command name
Résultat Command The current instance

configure() protected méthode

Configures the current command.
protected configure ( )

execute() protected méthode

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 execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : null | integer
$input Symfony\Component\Console\Input\InputInterface An InputInterface instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance
Résultat null | integer null or 0 if everything went fine, or an error code

getAliases() public méthode

Returns the aliases for the command.
public getAliases ( ) : array
Résultat array An array of aliases for the command

getApplication() public méthode

Gets the application instance for this command.
public getApplication ( ) : Application
Résultat Symfony\Component\Console\Application An Application instance

getDefinition() public méthode

Gets the InputDefinition attached to this Command.
public getDefinition ( ) : Symfony\Component\Console\Input\InputDefinition
Résultat Symfony\Component\Console\Input\InputDefinition An InputDefinition instance

getDescription() public méthode

Returns the description for the command.
public getDescription ( ) : string
Résultat string The description for the command

getHelp() public méthode

Returns the help for the command.
public getHelp ( ) : string
Résultat string The help for the command

getHelper() public méthode

Gets a helper instance by name.
public getHelper ( string $name ) : mixed
$name string The helper name
Résultat mixed The helper value

getHelperSet() public méthode

Gets the helper set.
public getHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet
Résultat Symfony\Component\Console\Helper\HelperSet A HelperSet instance

getName() public méthode

Returns the command name.
public getName ( ) : string
Résultat string The command name

getNativeDefinition() public méthode

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 getNativeDefinition ( ) : Symfony\Component\Console\Input\InputDefinition
Résultat Symfony\Component\Console\Input\InputDefinition An InputDefinition instance

getProcessedHelp() public méthode

Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.
public getProcessedHelp ( ) : string
Résultat string The processed help for the command

getSynopsis() public méthode

Returns the synopsis for the command.
public getSynopsis ( boolean $short = false ) : string
$short boolean Whether to show the short version of the synopsis (with options folded) or not
Résultat string The synopsis

getUsages() public méthode

Returns alternative usages of the command.
public getUsages ( ) : array
Résultat array

ignoreValidationErrors() public méthode

This is mainly useful for the help command.

initialize() protected méthode

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 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 méthode

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 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 méthode

Override this to check for x or y and return false if the command can not run properly under the current conditions.
public isEnabled ( ) : boolean
Résultat boolean

isHidden() public méthode

public isHidden ( ) : boolean
Résultat boolean Whether the command should be publicly shown or not.

mergeApplicationDefinition() public méthode

This method is not part of public API and should not be used directly.
public mergeApplicationDefinition ( boolean $mergeArgs = true )
$mergeArgs boolean Whether to merge or not the Application definition arguments to Command definition arguments

run() public méthode

The code to execute is either defined directly with the setCode() method or by overriding the execute() method in a sub-class.
See also: setCode()
See also: execute()
public run ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer
$input Symfony\Component\Console\Input\InputInterface An InputInterface instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance
Résultat integer The command exit code

setAliases() public méthode

Sets the aliases for the command.
public setAliases ( string[] $aliases ) : Command
$aliases string[] An array of aliases for the command
Résultat Command The current instance

setApplication() public méthode

Sets the application instance for this command.
public setApplication ( Application $application = null )
$application Symfony\Component\Console\Application An Application instance

setCode() public méthode

If this method is used, it overrides the code defined in the execute() method.
See also: execute()
public setCode ( callable $code ) : Command
$code callable A callable(InputInterface $input, OutputInterface $output)
Résultat Command The current instance

setDefinition() public méthode

Sets an array of argument and option instances.
public setDefinition ( array | Symfony\Component\Console\Input\InputDefinition $definition ) : Command
$definition array | Symfony\Component\Console\Input\InputDefinition An array of argument and option instances or a definition instance
Résultat Command The current instance

setDescription() public méthode

Sets the description for the command.
public setDescription ( string $description ) : Command
$description string The description for the command
Résultat Command The current instance

setHelp() public méthode

Sets the help for the command.
public setHelp ( string $help ) : Command
$help string The help for the command
Résultat Command The current instance

setHelperSet() public méthode

Sets the helper set.
public setHelperSet ( Symfony\Component\Console\Helper\HelperSet $helperSet )
$helperSet Symfony\Component\Console\Helper\HelperSet A HelperSet instance

setHidden() public méthode

public setHidden ( boolean $hidden ) : Command
$hidden boolean Whether or not the command should be hidden from the list of commands
Résultat Command The current instance

setName() public méthode

This method can set both the namespace and the name if you separate them by a colon (:) $command->setName('foo:bar');
public setName ( string $name ) : Command
$name string The command name
Résultat Command The current instance

setProcessTitle() public méthode

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 setProcessTitle ( string $title ) : Command
$title string The process title
Résultat Command The current instance