PHP Класс Symfony\Component\Console\Command\Command

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
validateName ( string $name ) Validates a command name.

Описание методов

__construct() публичный метод

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() публичный метод

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)
Результат Command The current instance

addOption() публичный метод

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)
Результат Command The current instance

addUsage() публичный метод

Add a command usage example.
public addUsage ( string $usage ) : Command
$usage string The usage, it'll be prefixed with the command name
Результат Command The current instance

configure() защищенный метод

Configures the current command.
protected configure ( )

execute() защищенный метод

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.
См. также: 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
Результат null | integer null or 0 if everything went fine, or an error code

getAliases() публичный метод

Returns the aliases for the command.
public getAliases ( ) : array
Результат array An array of aliases for the command

getApplication() публичный метод

Gets the application instance for this command.
public getApplication ( ) : Application
Результат Symfony\Component\Console\Application An Application instance

getDefinition() публичный метод

Gets the InputDefinition attached to this Command.
public getDefinition ( ) : Symfony\Component\Console\Input\InputDefinition
Результат Symfony\Component\Console\Input\InputDefinition An InputDefinition instance

getDescription() публичный метод

Returns the description for the command.
public getDescription ( ) : string
Результат string The description for the command

getHelp() публичный метод

Returns the help for the command.
public getHelp ( ) : string
Результат string The help for the command

getHelper() публичный метод

Gets a helper instance by name.
public getHelper ( string $name ) : mixed
$name string The helper name
Результат mixed The helper value

getHelperSet() публичный метод

Gets the helper set.
public getHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet
Результат Symfony\Component\Console\Helper\HelperSet A HelperSet instance

getName() публичный метод

Returns the command name.
public getName ( ) : string
Результат string The command name

getNativeDefinition() публичный метод

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
Результат Symfony\Component\Console\Input\InputDefinition An InputDefinition instance

getProcessedHelp() публичный метод

Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.
public getProcessedHelp ( ) : string
Результат string The processed help for the command

getSynopsis() публичный метод

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
Результат string The synopsis

getUsages() публичный метод

Returns alternative usages of the command.
public getUsages ( ) : array
Результат array

ignoreValidationErrors() публичный метод

This is mainly useful for the help command.

initialize() защищенный метод

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() защищенный метод

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() публичный метод

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
Результат boolean

isHidden() публичный метод

public isHidden ( ) : boolean
Результат boolean Whether the command should be publicly shown or not.

mergeApplicationDefinition() публичный метод

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() публичный метод

The code to execute is either defined directly with the setCode() method or by overriding the execute() method in a sub-class.
См. также: setCode()
См. также: 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
Результат integer The command exit code

setAliases() публичный метод

Sets the aliases for the command.
public setAliases ( string[] $aliases ) : Command
$aliases string[] An array of aliases for the command
Результат Command The current instance

setApplication() публичный метод

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

setCode() публичный метод

If this method is used, it overrides the code defined in the execute() method.
См. также: execute()
public setCode ( callable $code ) : Command
$code callable A callable(InputInterface $input, OutputInterface $output)
Результат Command The current instance

setDefinition() публичный метод

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
Результат Command The current instance

setDescription() публичный метод

Sets the description for the command.
public setDescription ( string $description ) : Command
$description string The description for the command
Результат Command The current instance

setHelp() публичный метод

Sets the help for the command.
public setHelp ( string $help ) : Command
$help string The help for the command
Результат Command The current instance

setHelperSet() публичный метод

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

setHidden() публичный метод

public setHidden ( boolean $hidden ) : Command
$hidden boolean Whether or not the command should be hidden from the list of commands
Результат Command The current instance

setName() публичный метод

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
Результат Command The current instance

setProcessTitle() публичный метод

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
Результат Command The current instance