类 CompletionCommand
为 bash 等命令行提供自动补全功能。
属性概要
- 
        $_eventClass protectedstring新事件对象的默认类名。 
- 
        $_eventManager protectedCake\Event\EventManagerInterface|nullCake\Event\EventManager 实例,用于分发内部事件。 
- 
        $_tableLocator protectedCake\ORM\Locator\LocatorInterface|null表定位器实例 
- 
        $commands protectedCake\Console\CommandCollection
- 
        $defaultTable protectedstring|null该对象的默认表别名。 
- 
        $name protectedstring该命令的名称。 
方法概要
- 
          abort() public使用 StopException 停止当前进程。 
- 
          buildOptionParser() public获取选项解析器实例并进行配置。 
- 
          defaultName() public static获取命令名称。 
- 
          dispatchEvent() public用于创建和分发事件的包装器。 
- 
          displayHelp() protected输出帮助内容 
- 
          execute() public主函数 打印命令列表。 
- 
          executeCommand() public使用提供的参数集执行另一个命令。 
- 
          fetchTable() public获取表实例的便捷方法。 
- 
          getCommands() protected获取已定义的命令列表。 
- 
          getDescription() public static获取命令描述。 
- 
          getEventManager() public返回该对象的 Cake\Event\EventManager 管理器实例。 
- 
          getName() public获取命令名称。 
- 
          getOptionParser() public获取选项解析器。 
- 
          getOptions() protected获取命令或子命令的选项 
- 
          getRootName() public获取根命令名称。 
- 
          getSubcommands() protected获取已定义的子命令列表。 
- 
          getTableLocator() public获取表定位器。 
- 
          initialize() publicCakePHP 在执行命令之前调用的钩子方法。 
- 
          log() public将消息写入日志的便捷方法。有关写入日志的更多信息,请参见 Log::write()。 
- 
          run() public运行命令。 
- 
          setCommandCollection() public设置用于获取补全数据的命令集合。 
- 
          setEventManager() public返回该对象的 Cake\Event\EventManagerInterface 实例。 
- 
          setName() public设置该命令在集合中使用的名称。 
- 
          setOutputLevel() protected根据参数设置输出级别。 
- 
          setTableLocator() public设置表定位器。 
方法详情
abort() ¶ public
abort(int $code = self::CODE_ERROR): never使用 StopException 停止当前进程。
参数
- 
                int$code optional
- 要使用的退出代码。 
返回
never抛出
Cake\Console\Exception\StopExceptionbuildOptionParser() ¶ public
buildOptionParser(Cake\Console\ConsoleOptionParser $parser): Cake\Console\ConsoleOptionParser获取选项解析器实例并进行配置。
参数
- 
                Cake\Console\ConsoleOptionParser$parser
- 要构建的解析器 
返回
Cake\Console\ConsoleOptionParserdefaultName() ¶ public static
defaultName(): string获取命令名称。
根据类名返回命令名称。例如,对于类名为 UpdateTableCommand 的命令,返回的默认名称将为 'update_table'。
返回
stringdispatchEvent() ¶ public
dispatchEvent(string $name, array $data = [], TSubject|null $subject = null): Cake\Event\EventInterface<TSubject>用于创建和分发事件的包装器。
返回一个已分发的事件。
参数
- 
                string$name
- 事件名称。 
- 
                array$data optional
- 您希望通过此事件传递的任何值,监听器都可以读取这些值。 
- 
                TSubject|null$subject optional
- 此事件适用的对象(默认情况下为 $this)。 
返回
Cake\Event\EventInterface<TSubject>displayHelp() ¶ protected
displayHelp(Cake\Console\ConsoleOptionParser $parser, Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): void输出帮助内容
参数
- 
                Cake\Console\ConsoleOptionParser$parser
- 选项解析器。 
- 
                Cake\Console\Arguments$args
- 命令参数。 
- 
                Cake\Console\ConsoleIo$io
- 控制台输入输出 
返回
voidexecute() ¶ public
execute(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): int|null主函数 打印命令列表。
参数
- 
                Cake\Console\Arguments$args
- 命令参数。 
- 
                Cake\Console\ConsoleIo$io
- 控制台输入输出 
返回
int|nullexecuteCommand() ¶ public
executeCommand(Cake\Console\CommandInterface|string $command, array $args = [], Cake\Console\ConsoleIo|null $io = null): int|null使用提供的参数集执行另一个命令。
如果您使用的是字符串命令名称,则该命令的依赖项不会使用应用程序容器进行解析。相反,您需要将命令作为包含所有依赖项的对象传递。
参数
- 
                Cake\Console\CommandInterface|string$command
- 命令类名或命令实例。 
- 
                array$args optional
- 用于调用命令的参数。 
- 
                Cake\Console\ConsoleIo|null$io optional
- 用于执行命令的 ConsoleIo 实例。 
返回
int|nullfetchTable() ¶ public
fetchTable(string|null $alias = null, array<string, mixed> $options = []): Cake\ORM\Table获取表实例的便捷方法。
参数
- 
                string|null$alias 可选
- 您想要获取的别名。应为驼峰式命名法。如果为 - null,则使用 $defaultTable 属性的值。
- 
                array<string, mixed>$options 可选
- 您想要用来构建表的选项。如果表已加载,则会忽略注册表选项。 
返回
Cake\ORM\Table抛出
Cake\Core\Exception\CakeException如果 `$alias` 参数和 `$defaultTable` 属性都为 `null`。
另请参阅
getCommands() ¶ protected
getCommands(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): int获取已定义的命令列表。
参数
- 
                Cake\Console\Arguments$args
- 命令参数。 
- 
                Cake\Console\ConsoleIo$io
- 控制台输入输出 
返回
intgetEventManager() ¶ public
getEventManager(): Cake\Event\EventManagerInterface返回该对象的 Cake\Event\EventManager 管理器实例。
您可以使用此实例向对象事件注册任何新的侦听器或回调,或创建自己的事件并根据需要触发它们。
返回
Cake\Event\EventManagerInterfacegetOptionParser() ¶ public
getOptionParser(): Cake\Console\ConsoleOptionParser获取选项解析器。
您可以覆盖 buildOptionParser() 来定义您的选项和参数。
返回
Cake\Console\ConsoleOptionParser抛出
Cake\Core\Exception\CakeException当解析器无效时
getOptions() ¶ protected
getOptions(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): int|null获取命令或子命令的选项
参数
- 
                Cake\Console\Arguments$args
- 命令参数。 
- 
                Cake\Console\ConsoleIo$io
- 控制台输入输出 
返回
int|nullgetSubcommands() ¶ protected
getSubcommands(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): int获取已定义的子命令列表。
参数
- 
                Cake\Console\Arguments$args
- 命令参数。 
- 
                Cake\Console\ConsoleIo$io
- 控制台输入输出 
返回
intgetTableLocator() ¶ public
getTableLocator(): Cake\ORM\Locator\LocatorInterface获取表定位器。
返回
Cake\ORM\Locator\LocatorInterfaceinitialize() ¶ public
initialize(): voidCakePHP 在执行命令之前调用的钩子方法。
覆盖此方法并实现代价高昂或重要的设置步骤,这些步骤不应在每次命令运行时运行。此方法将在选项和参数验证和处理之前调用。
返回
voidlog() ¶ public
log(Stringable|string $message, string|int $level = LogLevel::ERROR, array|string $context = []): bool将消息写入日志的便捷方法。有关写入日志的更多信息,请参见 Log::write()。
参数
- 
                Stringable|string$message
- 日志消息。 
- 
                string|int$level 可选
- 错误级别。 
- 
                array|string$context 可选
- 与此消息相关的其他日志数据。 
返回
boolrun() ¶ public
run(array $argv, Cake\Console\ConsoleIo $io): int|null运行命令。
参数
- 
                array$argv
- 
                Cake\Console\ConsoleIo$io
返回
int|nullsetCommandCollection() ¶ public
setCommandCollection(Cake\Console\CommandCollection $commands): void设置用于获取补全数据的命令集合。
参数
- 
                Cake\Console\CommandCollection$commands
- 命令集合 
返回
voidsetEventManager() ¶ public
setEventManager(Cake\Event\EventManagerInterface $eventManager): $this返回该对象的 Cake\Event\EventManagerInterface 实例。
您可以使用此实例向对象事件注册任何新的侦听器或回调,或创建自己的事件并根据需要触发它们。
参数
- 
                Cake\Event\EventManagerInterface$eventManager
- 要设置的事件管理器 
返回
$thissetName() ¶ public
setName(string $name): $this设置该命令在集合中使用的名称。
通常由 CommandCollection 在添加命令时调用。要求名称中至少包含一个空格,以便可以计算根命令。
参数
- 
                string$name
返回
$thissetOutputLevel() ¶ protected
setOutputLevel(Cake\Console\Arguments $args, Cake\Console\ConsoleIo $io): void根据参数设置输出级别。
参数
- 
                Cake\Console\Arguments$args
- 命令参数。 
- 
                Cake\Console\ConsoleIo$io
- 控制台输入输出 
返回
voidsetTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this设置表定位器。
参数
- 
                Cake\ORM\Locator\LocatorInterface$tableLocator
- LocatorInterface 实例。 
返回
$this属性详情
$_eventManager ¶ protected
Cake\Event\EventManager 实例,用于分发内部事件。
类型
Cake\Event\EventManagerInterface|null