PHP Class Webmozart\Console\Api\Command\Command

A Command object contains all the information that is necessary to describe and run a console command. Use the {@link CommandConfig} class to configure a command: php $config = CommandConfig::create() ->setDescription('List and manage servers') ->beginSubCommand('add') ->setDescription('Add a new server') ->addArgument('host', InputArgument::REQUIRED) ->addOption('port', 'p', InputOption::VALUE_OPTIONAL, null, 80) ->end() ; $command = new Command($config);
Since: 1.0
Author: Bernhard Schussek ([email protected])
Afficher le fichier Open project: webmozart/console Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( CommandConfig $config, Webmozart\Console\Api\Application\Application $application = null, Command $parentCommand = null ) Creates a new command.
getAliases ( ) : string[] Returns the alias names of the command.
getApplication ( ) : Webmozart\Console\Api\Application\Application Returns the console application.
getArgsFormat ( ) : ArgsFormat Returns the arguments format of the command.
getConfig ( ) : CommandConfig Returns the configuration of the command.
getDefaultSubCommands ( ) : CommandCollection Returns the commands that should be executed if no explicit command is passed.
getName ( ) : string Returns the name of the command.
getNamedSubCommands ( ) : CommandCollection Returns all sub-commands that are not anonymous.
getParentCommand ( ) : Command Returns the parent command.
getShortName ( ) : string | null Returns the short name of the command.
getSubCommand ( string $name ) : Command Returns the sub-command with a specific name.
getSubCommands ( ) : CommandCollection Returns all sub-commands of the command.
handle ( Args $args, IO $io ) : integer Executes the command for the given parsed arguments.
hasAliases ( ) : boolean Returns whether the command has aliases.
hasDefaultSubCommands ( ) : boolean Returns whether the command has any default commands.
hasNamedSubCommands ( ) : boolean Returns whether the command has any commands that are not anonymous.
hasSubCommand ( string $name ) : boolean Returns whether a sub-command with the given name exists.
hasSubCommands ( ) : boolean Returns whether the command has any sub-commands.
parseArgs ( Webmozart\Console\Api\Args\RawArgs $args, boolean $lenient = null ) : Args Parses the raw console arguments and returns the parsed arguments.
run ( Webmozart\Console\Api\Args\RawArgs $args, IO $io ) : integer Executes the command for the given unparsed arguments.

Private Methods

Méthode Description
addSubCommand ( SubCommandConfig $config ) Adds a sub-command.
doHandle ( Args $args, IO $io )
getBaseFormat ( ) : ArgsFormat Returns the inherited arguments format of the command.
validateSubCommandName ( SubCommandConfig $config )
warnIfProcessTitleNotSupported ( $processTitle, IO $io )

Method Details

__construct() public méthode

Creates a new command.
public __construct ( CommandConfig $config, Webmozart\Console\Api\Application\Application $application = null, Command $parentCommand = null )
$config Webmozart\Console\Api\Config\CommandConfig The command configuration.
$application Webmozart\Console\Api\Application\Application The console application.
$parentCommand Command The parent command.

getAliases() public méthode

Returns the alias names of the command.
public getAliases ( ) : string[]
Résultat string[] An array of alias names of the command.

getApplication() public méthode

Returns the console application.
public getApplication ( ) : Webmozart\Console\Api\Application\Application
Résultat Webmozart\Console\Api\Application\Application The console application.

getArgsFormat() public méthode

Returns the arguments format of the command.
public getArgsFormat ( ) : ArgsFormat
Résultat Webmozart\Console\Api\Args\Format\ArgsFormat The input definition.

getConfig() public méthode

Returns the configuration of the command.
public getConfig ( ) : CommandConfig
Résultat Webmozart\Console\Api\Config\CommandConfig The command configuration.

getDefaultSubCommands() public méthode

Returns the commands that should be executed if no explicit command is passed.
public getDefaultSubCommands ( ) : CommandCollection
Résultat CommandCollection The default commands.

getName() public méthode

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

getNamedSubCommands() public méthode

Returns all sub-commands that are not anonymous.
public getNamedSubCommands ( ) : CommandCollection
Résultat CommandCollection The named commands.

getParentCommand() public méthode

Returns the parent command.
public getParentCommand ( ) : Command
Résultat Command The parent command.

getShortName() public méthode

This method only returns a value if an {@link OptionCommandConfig} was passed to the constructor. Otherwise this method returns null.
public getShortName ( ) : string | null
Résultat string | null The short name or `null` if the command is not an option command.

getSubCommand() public méthode

Returns the sub-command with a specific name.
public getSubCommand ( string $name ) : Command
$name string The name of the sub-command.
Résultat Command The sub-command.

getSubCommands() public méthode

Returns all sub-commands of the command.
public getSubCommands ( ) : CommandCollection
Résultat CommandCollection The sub-commands.

handle() public méthode

Executes the command for the given parsed arguments.
public handle ( Args $args, IO $io ) : integer
$args Webmozart\Console\Api\Args\Args The parsed console arguments.
$io Webmozart\Console\Api\IO\IO The I/O.
Résultat integer Returns 0 on success and any other integer on error.

hasAliases() public méthode

Returns whether the command has aliases.
public hasAliases ( ) : boolean
Résultat boolean Returns `true` if the command has aliases and `false` otherwise.

hasDefaultSubCommands() public méthode

Returns whether the command has any default commands.
See also: getDefaultSubCommands()
public hasDefaultSubCommands ( ) : boolean
Résultat boolean Returns `true` if the command has default commands and `false` otherwise.

hasNamedSubCommands() public méthode

Returns whether the command has any commands that are not anonymous.
See also: getNamedSubCommands()
public hasNamedSubCommands ( ) : boolean
Résultat boolean Returns `true` if the command has named commands and `false` otherwise.

hasSubCommand() public méthode

Returns whether a sub-command with the given name exists.
public hasSubCommand ( string $name ) : boolean
$name string The name of the sub-command.
Résultat boolean Returns `true` if a sub-command with that name exists and `false` otherwise.

hasSubCommands() public méthode

Returns whether the command has any sub-commands.
public hasSubCommands ( ) : boolean
Résultat boolean Returns `true` if the command has sub-commands and `false` otherwise.

parseArgs() public méthode

Parses the raw console arguments and returns the parsed arguments.
public parseArgs ( Webmozart\Console\Api\Args\RawArgs $args, boolean $lenient = null ) : Args
$args Webmozart\Console\Api\Args\RawArgs The raw console arguments.
$lenient boolean Whether the parser should ignore parse errors. If `true`, the parser will not throw any exceptions when parse errors occur.
Résultat Webmozart\Console\Api\Args\Args The parsed console arguments.

run() public méthode

Executes the command for the given unparsed arguments.
public run ( Webmozart\Console\Api\Args\RawArgs $args, IO $io ) : integer
$args Webmozart\Console\Api\Args\RawArgs The unparsed console arguments.
$io Webmozart\Console\Api\IO\IO The I/O.
Résultat integer Returns 0 on success and any other integer on error.