Class CompletionCommand
Provide command completion shells such as bash.
Property Summary
- 
        $_modelFactories protected(callable|Cake\Datasource\Locator\LocatorInterface)[]A list of overridden model factory functions. 
- 
        $_modelType protectedstringThe model type to use. 
- 
        $_tableLocator protectedCake\ORM\Locator\LocatorInterface|nullTable locator instance 
- 
        $commands protectedCake\Console\CommandCollection
- 
        $modelClass protectedstring|nullThis object's primary model class name. Should be a plural form. CakePHP will not inflect the name. 
- 
        $name protectedstringThe name of this command. 
Method Summary
- 
          __construct() publicConstructor 
- 
          _setModelClass() protectedSet the modelClass property based on conventions. 
- 
          abort() publicHalt the the current process with a StopException. 
- 
          buildOptionParser() publicGets the option parser instance and configures it. 
- 
          defaultName() public staticGet the command name. 
- 
          displayHelp() protectedOutput help content 
- 
          execute() publicMain function Prints out the list of commands. 
- 
          executeCommand() publicExecute another command with the provided set of arguments. 
- 
          getCommands() protectedGet the list of defined commands. 
- 
          getModelType() publicGet the model type to be used by this class 
- 
          getName() publicGet the command name. 
- 
          getOptionParser() publicGet the option parser. 
- 
          getOptions() protectedGet the options for a command or subcommand 
- 
          getRootName() publicGet the root command name. 
- 
          getSubcommands() protectedGet the list of defined sub-commands. 
- 
          getTableLocator() publicGets the table locator. 
- 
          initialize() publicHook method invoked by CakePHP when a command is about to be executed. 
- 
          loadModel() publicLoads and constructs repository objects required by this object 
- 
          log() publicConvenience method to write a message to Log. See Log::write() for more information on writing to logs. 
- 
          modelFactory() publicOverride a existing callable to generate repositories of a given type. 
- 
          run() publicRun the command. 
- 
          setCommandCollection() publicSet the command collection used to get completion data on. 
- 
          setModelType() publicSet the model type to be used by this class 
- 
          setName() publicSet the name this command uses in the collection. 
- 
          setOutputLevel() protectedSet the output level based on the Arguments. 
- 
          setTableLocator() publicSets the table locator. 
- 
          shellSubcommands() protectedReflect the subcommands names out of a shell. 
Method Detail
__construct() ¶ public
__construct()Constructor
By default CakePHP will construct command objects when building the CommandCollection for your application.
_setModelClass() ¶ protected
_setModelClass(string $name): voidSet the modelClass property based on conventions.
If the property is already set it will not be overwritten
Parameters
- 
                string$name
- Class name. 
Returns
voidabort() ¶ public
abort(int $code = self::CODE_ERROR): voidHalt the the current process with a StopException.
Parameters
- 
                int$code optional
- The exit code to use. 
Returns
voidThrows
Cake\Console\Exception\StopExceptionbuildOptionParser() ¶ public
buildOptionParser(Cake\Console\ConsoleOptionParser $parser): Cake\Console\ConsoleOptionParserGets the option parser instance and configures it.
Parameters
- 
                Cake\Console\ConsoleOptionParser$parser
- The parser to build 
Returns
Cake\Console\ConsoleOptionParserdefaultName() ¶ public static
defaultName(): stringGet 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'.
Returns
stringdisplayHelp() ¶ protected
displayHelp(Cake\Console\ConsoleOptionParser $parser, Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): voidOutput help content
Parameters
- 
                Cake\Console\ConsoleOptionParser$parser
- The option parser. 
- 
                Cake\Console\Arguments$args
- The command arguments. 
- 
                Cake\Console\ConsoleIo$io
- The console io 
Returns
voidexecute() ¶ public
execute(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): intMain function Prints out the list of commands.
Parameters
- 
                Cake\Console\Arguments$args
- The command arguments. 
- 
                Cake\Console\ConsoleIo$io
- The console io 
Returns
intexecuteCommand() ¶ public
executeCommand(string|Cake\Console\CommandInterface $command, array $args = [], Cake\Console\ConsoleIo $io = null): int|nullExecute another command with the provided set of arguments.
Parameters
- 
                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. 
Returns
int|nullThe exit code or null for success of the command.
getCommands() ¶ protected
getCommands(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): intGet the list of defined commands.
Parameters
- 
                Cake\Console\Arguments$args
- The command arguments. 
- 
                Cake\Console\ConsoleIo$io
- The console io 
Returns
intgetModelType() ¶ public
getModelType(): stringGet the model type to be used by this class
Returns
stringgetOptionParser() ¶ public
getOptionParser(): Cake\Console\ConsoleOptionParserGet the option parser.
You can override buildOptionParser() to define your options & arguments.
Returns
Cake\Console\ConsoleOptionParserThrows
RuntimeExceptionWhen the parser is invalid
getOptions() ¶ protected
getOptions(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): intGet the options for a command or subcommand
Parameters
- 
                Cake\Console\Arguments$args
- The command arguments. 
- 
                Cake\Console\ConsoleIo$io
- The console io 
Returns
intgetSubcommands() ¶ protected
getSubcommands(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): intGet the list of defined sub-commands.
Parameters
- 
                Cake\Console\Arguments$args
- The command arguments. 
- 
                Cake\Console\ConsoleIo$io
- The console io 
Returns
intgetTableLocator() ¶ public
getTableLocator(): Cake\ORM\Locator\LocatorInterfaceGets the table locator.
Returns
Cake\ORM\Locator\LocatorInterfaceinitialize() ¶ public
initialize(): voidHook 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.
Returns
voidloadModel() ¶ public
loadModel(string|null $modelClass = null, string|null $modelType = null): Cake\Datasource\RepositoryInterfaceLoads and constructs repository objects required by this object
Typically used to load ORM Table objects as required. Can also be used to load other types of repository objects your application uses.
If a repository provider does not return an object a MissingModelException will be thrown.
Parameters
- 
                string|null$modelClass optional
- Name of model class to load. Defaults to $this->modelClass. The name can be an alias like - 'Post'or FQCN like- App\Model\Table\PostsTable::class.
- 
                string|null$modelType optional
- The type of repository to load. Defaults to the getModelType() value. 
Returns
Cake\Datasource\RepositoryInterfaceThe model instance created.
Throws
Cake\Datasource\Exception\MissingModelExceptionIf the model class cannot be found.
UnexpectedValueExceptionIf $modelClass argument is not provided and ModelAwareTrait::$modelClass property value is empty.
log() ¶ public
log(string $message, int|string $level = LogLevel::ERROR, string|array $context = []): boolConvenience method to write a message to Log. See Log::write() for more information on writing to logs.
Parameters
- 
                string$message
- Log message. 
- 
                int|string$level optional
- Error level. 
- 
                string|array$context optional
- Additional log data relevant to this message. 
Returns
boolSuccess of log write.
modelFactory() ¶ public
modelFactory(string $type, callable|Cake\Datasource\Locator\LocatorInterface $factory): voidOverride a existing callable to generate repositories of a given type.
Parameters
- 
                string$type
- The name of the repository type the factory function is for. 
- 
                callable|Cake\Datasource\Locator\LocatorInterface$factory
- The factory function used to create instances. 
Returns
voidrun() ¶ public
run(array $argv, Cake\Console\ConsoleIo $io): int|nullRun the command.
Parameters
- 
                array$argv
- 
                Cake\Console\ConsoleIo$io
Returns
int|nullsetCommandCollection() ¶ public
setCommandCollection(Cake\Console\CommandCollection $commands): voidSet the command collection used to get completion data on.
Parameters
- 
                Cake\Console\CommandCollection$commands
- The command collection 
Returns
voidsetModelType() ¶ public
setModelType(string $modelType): $thisSet the model type to be used by this class
Parameters
- 
                string$modelType
- The model type 
Returns
$thissetName() ¶ public
setName(string $name): $thisSet 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.
Parameters
- 
                string$name
Returns
$thissetOutputLevel() ¶ protected
setOutputLevel(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): voidSet the output level based on the Arguments.
Parameters
- 
                Cake\Console\Arguments$args
- The command arguments. 
- 
                Cake\Console\ConsoleIo$io
- The console io 
Returns
voidsetTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $thisSets the table locator.
Parameters
- 
                Cake\ORM\Locator\LocatorInterface$tableLocator
- LocatorInterface instance. 
Returns
$thisshellSubcommands() ¶ protected
shellSubcommands(Cake\Console\Shell $shell): string[]Reflect the subcommands names out of a shell.
Parameters
- 
                Cake\Console\Shell$shell
- The shell to get commands for 
Returns
string[]A list of commands
Property Detail
$_modelFactories ¶ protected
A list of overridden model factory functions.
Type
(callable|Cake\Datasource\Locator\LocatorInterface)[]$modelClass ¶ protected
This object's primary model class name. Should be a plural form. CakePHP will not inflect the name.
Example: For an object named 'Comments', the modelClass would be 'Comments'.
Plugin classes should use Plugin.Comments style names to correctly load
models from the correct plugin.
Use empty string to not use auto-loading on this object. Null auto-detects based on controller name.
Type
string|null