class Command
Base class for all commands.
Methods
__construct(string|null $name = null) Constructor. | ||
ignoreValidationErrors() Ignores validation errors. | ||
setApplication(Application $application = null) Sets the application instance for this command. | ||
setHelperSet(HelperSet $helperSet) Sets the helper set. | ||
HelperSet | getHelperSet() Gets the helper set. | |
Application | getApplication() Gets the application instance for this command. | |
bool | isEnabled() Checks whether the command is enabled or not in the current environment. | |
int | run(InputInterface $input, OutputInterface $output) Runs the command. | |
Command | setCode(callable $code) Sets the code to execute when running this command. | |
mergeApplicationDefinition(bool $mergeArgs = true) Merges the application definition with the command definition. | ||
Command | setDefinition(array|InputDefinition $definition) Sets an array of argument and option instances. | |
InputDefinition | getDefinition() Gets the InputDefinition attached to this Command. | |
InputDefinition | getNativeDefinition() Gets the InputDefinition to be used to create representations of this Command. | |
Command | addArgument(string $name, int $mode = null, string $description = '', mixed $default = null) Adds an argument. | |
Command | addOption(string $name, string $shortcut = null, int $mode = null, string $description = '', mixed $default = null) Adds an option. | |
Command | setName(string $name) Sets the name of the command. | |
Command | setProcessTitle(string $title) Sets the process title of the command. | |
string | getName() Returns the command name. | |
Command | setDescription(string $description) Sets the description for the command. | |
string | getDescription() Returns the description for the command. | |
Command | setHelp(string $help) Sets the help for the command. | |
string | getHelp() Returns the help for the command. | |
string | getProcessedHelp() Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically. | |
Command | setAliases(string[] $aliases) Sets the aliases for the command. | |
array | getAliases() Returns the aliases for the command. | |
string | getSynopsis(bool $short = false) Returns the synopsis for the command. | |
Command | addUsage(string $usage) Add a command usage example. | |
array | getUsages() Returns alternative usages of the command. | |
mixed | getHelper(string $name) Gets a helper instance by name. |
Details
__construct(string|null $name = null)
Constructor.
ignoreValidationErrors()
Ignores validation errors.
This is mainly useful for the help command.
setApplication(Application $application = null)
Sets the application instance for this command.
setHelperSet(HelperSet $helperSet)
Sets the helper set.
HelperSet getHelperSet()
Gets the helper set.
Application getApplication()
Gets the application instance for this command.
bool isEnabled()
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.
int run(InputInterface $input, OutputInterface $output)
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.
Command setCode(callable $code)
Sets the code to execute when running this command.
If this method is used, it overrides the code defined in the execute() method.
mergeApplicationDefinition(bool $mergeArgs = true)
Merges the application definition with the command definition.
This method is not part of public API and should not be used directly.
Command setDefinition(array|InputDefinition $definition)
Sets an array of argument and option instances.
InputDefinition getDefinition()
Gets the InputDefinition attached to this Command.
InputDefinition getNativeDefinition()
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.
Command addArgument(string $name, int $mode = null, string $description = '', mixed $default = null)
Adds an argument.
Command addOption(string $name, string $shortcut = null, int $mode = null, string $description = '', mixed $default = null)
Adds an option.
Command setName(string $name)
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');
Command setProcessTitle(string $title)
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
string getName()
Returns the command name.
Command setDescription(string $description)
Sets the description for the command.
string getDescription()
Returns the description for the command.
Command setHelp(string $help)
Sets the help for the command.
string getHelp()
Returns the help for the command.
string getProcessedHelp()
Returns the processed help for the command replacing the %command.name% and %command.full_name% patterns with the real values dynamically.
Command setAliases(string[] $aliases)
Sets the aliases for the command.
array getAliases()
Returns the aliases for the command.
string getSynopsis(bool $short = false)
Returns the synopsis for the command.
Command addUsage(string $usage)
Add a command usage example.
array getUsages()
Returns alternative usages of the command.
mixed getHelper(string $name)
Gets a helper instance by name.
Please login to continue.