Base class for console commands.
Provides hooks for common command features:
initialize Acts as a post-construct hook.buildOptionParser Build/Configure the option parser for your command.execute Execute your command with parsed Arguments and ConsoleIoint 1 int 0 stringThe name of this command.
abort(int $code)
Halt the the current process with a StopException.
int $code optional The exit code to use.
Cake\Console\Exception\StopExceptionbuildOptionParser(\Cake\Console\ConsoleOptionParser $parser)
Hook method for defining this command's option parser.
\Cake\Console\ConsoleOptionParser $parser The parser to be defined
\Cake\Console\ConsoleOptionParserThe built parser.
defaultName()
Get the command name.
Returns the command name based on class name. For e.g. for a command with class name UpdateTableCommand the default name returned would be 'update_table'.
stringdisplayHelp(\Cake\Console\ConsoleOptionParser $parser, \Cake\Console\Arguments $args, \Cake\Console\ConsoleIo $io)
Output help content
\Cake\Console\ConsoleOptionParser $parser The option parser.
\Cake\Console\Arguments $args The command arguments.
\Cake\Console\ConsoleIo $io The console io
execute(\Cake\Console\Arguments $args, \Cake\Console\ConsoleIo $io)
Implement this method with your command's logic.
\Cake\Console\Arguments $args The command arguments.
\Cake\Console\ConsoleIo $io The console io
int|null|voidThe exit code or null for success
executeCommand(mixed $command, array $args, ?\Cake\Console\ConsoleIo $io)
Execute another command with the provided set of arguments.
string|\Cake\Console\CommandInterface $command The command class name or command instance.
array $args optional The arguments to invoke the command with.
\Cake\Console\ConsoleIo $io optional The ConsoleIo instance to use for the executed command.
int|nullThe exit code or null for success of the command.
getName()
Get the command name.
stringgetOptionParser()
Get the option parser.
You can override buildOptionParser() to define your options & arguments.
\Cake\Console\ConsoleOptionParserRuntimeExceptiongetRootName()
Get the root command name.
stringinitialize()
Hook method invoked by CakePHP when a command is about to be executed.
Override this method and implement expensive/important setup steps that should not run on every command run. This method will be called before the options and arguments are validated and processed.
run(array $argv, \Cake\Console\ConsoleIo $io)
Run the command.
array $argv Arguments from the CLI environment.
\Cake\Console\ConsoleIo $io The console io
int|nullExit code or null for success.
setName(string $name)
Set the name this command uses in the collection.
Generally invoked by the CommandCollection when the command is added. Required to have at least one space in the name so that the root command can be calculated.
string $name The name the command uses in the collection.
$thisInvalidArgumentExceptionsetOutputLevel(\Cake\Console\Arguments $args, \Cake\Console\ConsoleIo $io)
Set the output level based on the Arguments.
\Cake\Console\Arguments $args The command arguments.
\Cake\Console\ConsoleIo $io The console io
The name of this command.
string
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Console.BaseCommand.html