PHP Класс 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);
С версии: 1.0
Автор: Bernhard Schussek ([email protected])
Показать файл Открыть проект Примеры использования класса

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

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

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

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

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

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

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

Returns the alias names of the command.
public getAliases ( ) : string[]
Результат string[] An array of alias names of the command.

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

Returns the console application.
public getApplication ( ) : Webmozart\Console\Api\Application\Application
Результат Webmozart\Console\Api\Application\Application The console application.

getArgsFormat() публичный Метод

Returns the arguments format of the command.
public getArgsFormat ( ) : ArgsFormat
Результат Webmozart\Console\Api\Args\Format\ArgsFormat The input definition.

getConfig() публичный Метод

Returns the configuration of the command.
public getConfig ( ) : CommandConfig
Результат Webmozart\Console\Api\Config\CommandConfig The command configuration.

getDefaultSubCommands() публичный Метод

Returns the commands that should be executed if no explicit command is passed.
public getDefaultSubCommands ( ) : CommandCollection
Результат CommandCollection The default commands.

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

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

getNamedSubCommands() публичный Метод

Returns all sub-commands that are not anonymous.
public getNamedSubCommands ( ) : CommandCollection
Результат CommandCollection The named commands.

getParentCommand() публичный Метод

Returns the parent command.
public getParentCommand ( ) : Command
Результат Command The parent command.

getShortName() публичный Метод

This method only returns a value if an {@link OptionCommandConfig} was passed to the constructor. Otherwise this method returns null.
public getShortName ( ) : string | null
Результат string | null The short name or `null` if the command is not an option command.

getSubCommand() публичный Метод

Returns the sub-command with a specific name.
public getSubCommand ( string $name ) : Command
$name string The name of the sub-command.
Результат Command The sub-command.

getSubCommands() публичный Метод

Returns all sub-commands of the command.
public getSubCommands ( ) : CommandCollection
Результат CommandCollection The sub-commands.

handle() публичный Метод

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.
Результат integer Returns 0 on success and any other integer on error.

hasAliases() публичный Метод

Returns whether the command has aliases.
public hasAliases ( ) : boolean
Результат boolean Returns `true` if the command has aliases and `false` otherwise.

hasDefaultSubCommands() публичный Метод

Returns whether the command has any default commands.
См. также: getDefaultSubCommands()
public hasDefaultSubCommands ( ) : boolean
Результат boolean Returns `true` if the command has default commands and `false` otherwise.

hasNamedSubCommands() публичный Метод

Returns whether the command has any commands that are not anonymous.
См. также: getNamedSubCommands()
public hasNamedSubCommands ( ) : boolean
Результат boolean Returns `true` if the command has named commands and `false` otherwise.

hasSubCommand() публичный Метод

Returns whether a sub-command with the given name exists.
public hasSubCommand ( string $name ) : boolean
$name string The name of the sub-command.
Результат boolean Returns `true` if a sub-command with that name exists and `false` otherwise.

hasSubCommands() публичный Метод

Returns whether the command has any sub-commands.
public hasSubCommands ( ) : boolean
Результат boolean Returns `true` if the command has sub-commands and `false` otherwise.

parseArgs() публичный Метод

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.
Результат Webmozart\Console\Api\Args\Args The parsed console arguments.

run() публичный Метод

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.
Результат integer Returns 0 on success and any other integer on error.