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
Default error code
int 0
Default success code
stringThe name of this command.
Halt the the current process with a StopException.
Hook method for defining this command's option parser.
Get the command name.
Output help content
Implement this method with your command's logic.
Execute another command with the provided set of arguments.
Get the command description.
Get the command name.
Get the option parser.
Get the root command name.
Hook method invoked by CakePHP when a command is about to be executed.
Run the command.
Set the name this command uses in the collection.
Set the output level based on the Arguments.
abort(int $code = self::CODE_ERROR): void
Halt the the current process with a StopException.
int $code optional The exit code to use.
voidCake\Console\Exception\StopExceptionbuildOptionParser(Cake\Console\ConsoleOptionParser $parser): Cake\Console\ConsoleOptionParser
Hook method for defining this command's option parser.
Cake\Console\ConsoleOptionParser $parser The parser to be defined
Cake\Console\ConsoleOptionParserdefaultName(): string
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): void
Output help content
Cake\Console\ConsoleOptionParser $parser The option parser.
Cake\Console\Arguments $args The command arguments.
Cake\Console\ConsoleIo $io The console io
voidexecute(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): int|null|void
Implement this method with your command's logic.
Cake\Console\Arguments $args The command arguments.
Cake\Console\ConsoleIo $io The console io
int|null|voidexecuteCommand(Cake\Console\CommandInterface|string $command, array $args = [], Cake\Console\ConsoleIo|null $io = null): int|null
Execute another command with the provided set of arguments.
If you are using a string command name, that command's dependencies will not be resolved with the application container. Instead you will need to pass the command as an object with all of its dependencies.
Cake\Console\CommandInterface|string $command The command class name or command instance.
array $args optional The arguments to invoke the command with.
Cake\Console\ConsoleIo|null $io optional The ConsoleIo instance to use for the executed command.
int|nullgetDescription(): string
Get the command description.
stringgetName(): string
Get the command name.
stringgetOptionParser(): Cake\Console\ConsoleOptionParser
Get the option parser.
You can override buildOptionParser() to define your options & arguments.
Cake\Console\ConsoleOptionParserRuntimeExceptiongetRootName(): string
Get the root command name.
stringinitialize(): void
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.
voidrun(array $argv, Cake\Console\ConsoleIo $io): int|null
Run the command.
array $argv Cake\Console\ConsoleIo $io int|nullsetName(string $name): $this
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 $thissetOutputLevel(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): void
Set the output level based on the Arguments.
Cake\Console\Arguments $args The command arguments.
Cake\Console\ConsoleIo $io The console io
voidThe 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.4/class-Cake.Console.BaseCommand.html