类 CommandRunner
为提供的应用程序运行 CLI 命令。
属性摘要
-
$_eventClass 受保护
字符串新事件对象的默认类名。
-
$_eventManager 受保护
Cake\Event\EventManagerInterface|nullCake\Event\EventManager 的实例,该对象用于调度内部事件。
-
$aliases 受保护
array<string, string>别名映射。
-
$app 受保护
Cake\Core\ConsoleApplicationInterface正在运行的应用程序控制台命令。
-
$factory 受保护
Cake\Console\CommandFactoryInterface|null正在运行的应用程序控制台命令。
-
$root 受保护
字符串根命令名称。默认为
cake。
方法摘要
-
__construct() 公共
构造函数
-
bootstrap() 受保护
应用程序引导包装器。
-
createCommand() 受保护
创建命令实例的包装器。
-
dispatchEvent() 公共
创建和调度事件的包装器。
-
getCommand() 受保护
获取给定命令名称的 shell 实例
-
getEventManager() 公共
获取应用程序的事件管理器或全局管理器。
-
loadRoutes() 受保护
确保应用程序的路由已加载。
-
longestCommandName() 受保护
构建集合中存在的最长命令名称
-
resolveName() 受保护
将命令名称解析为集合中存在的名称。
-
run() 公共
运行包含在 $argv 中的命令。
-
runCommand() 受保护
执行命令类。
-
setAliases() 公共
替换运行程序的整个别名映射。
-
setEventManager() 公共
获取/设置应用程序的事件管理器。
方法详情
__construct() ¶ 公共
__construct(Cake\Core\ConsoleApplicationInterface $app, string $root = 'cake', Cake\Console\CommandFactoryInterface|null $factory = null)
构造函数
参数
-
Cake\Core\ConsoleApplicationInterface$app 要运行 CLI 命令的应用程序。
-
字符串$root 可选 要从 argv 中删除的根命令名称。
-
Cake\Console\CommandFactoryInterface|null$factory 可选 命令工厂实例。
createCommand() ¶ 受保护
createCommand(string $className): Cake\Console\CommandInterface
创建命令实例的包装器。
参数
-
字符串$className 命令类名。
返回值
Cake\Console\CommandInterfacedispatchEvent() ¶ 公共
dispatchEvent(string $name, array $data = [], TSubject|null $subject = null): Cake\Event\EventInterface<TSubject>
创建和调度事件的包装器。
返回已分派的事件。
参数
-
字符串$name 事件的名称。
-
数组$data 可选 您希望随此事件一起传输的任何值,监听器都可以读取这些值。
-
TSubject|null$subject 可选 此事件适用的对象(默认情况下为 $this)。
返回值
Cake\Event\EventInterface<TSubject>getCommand() ¶ 受保护
getCommand(Cake\Console\ConsoleIo $io, Cake\Console\CommandCollection $commands, string $name): Cake\Console\CommandInterface
获取给定命令名称的 shell 实例
参数
-
Cake\Console\ConsoleIo$io 为创建的 shell 类创建的 IO 包装器。
-
Cake\Console\CommandCollection$commands 要从中查找 shell 的命令集合。
-
字符串$name 要查找的命令名称
返回值
Cake\Console\CommandInterfacegetEventManager() ¶ 公共
getEventManager(): Cake\Event\EventManagerInterface
获取应用程序的事件管理器或全局管理器。
您可以使用此实例将任何新的监听器或回调注册到对象事件,或者创建您自己的事件并按需触发它们。
返回值
Cake\Event\EventManagerInterfacelongestCommandName() ¶ 受保护
longestCommandName(Cake\Console\CommandCollection $commands, array $argv): array
构建集合中存在的最长命令名称
构建与定义的命令匹配的最长命令名称。这最多会遍历 3 个标记。
参数
-
Cake\Console\CommandCollection$commands 要检查的命令集合。
-
数组$argv CLI 参数。
返回值
数组resolveName() ¶ 受保护
resolveName(Cake\Console\CommandCollection $commands, Cake\Console\ConsoleIo $io, string|null $name): string
将命令名称解析为集合中存在的名称。
应用向后兼容的变音和别名。将逐步向前最多 3 个标记在 $argv 中,以在 CommandCollection 中生成命令名称。更具体的命令名称优先于不太具体的命令名称。
参数
-
Cake\Console\CommandCollection$commands 要检查的命令集合。
-
Cake\Console\ConsoleIo$io 用于错误的 ConsoleIo 对象。
-
字符串|null$name 来自 CLI 参数的名称。
返回值
字符串抛出
Cake\Console\Exception\MissingOptionExceptionrun() ¶ 公共
run(array $argv, Cake\Console\ConsoleIo|null $io = null): int
运行包含在 $argv 中的命令。
使用应用程序执行以下操作
- 引导应用程序
- 使用应用程序上的 console() 钩子创建 CommandCollection。
- 触发自动连接插件的
Console.buildCommands事件。 - 运行请求的命令。
参数
-
数组$argv 来自 CLI 环境的参数。
-
Cake\Console\ConsoleIo|null$io 可选 ConsoleIo 实例。主要用于测试。
返回值
intrunCommand() ¶ 受保护
runCommand(Cake\Console\CommandInterface $command, array $argv, Cake\Console\ConsoleIo $io): int|null
执行命令类。
参数
-
Cake\Console\CommandInterface$command 要运行的命令。
-
数组$argv 要调用的 CLI 参数。
-
Cake\Console\ConsoleIo$io 控制台 io
返回值
int|nullsetAliases() ¶ 公共
setAliases(array<string, string> $aliases): $this
替换运行程序的整个别名映射。
别名允许您为集合中的命令定义备用名称。这对于添加顶级开关(如 --version 或 -h)很有用
用法
$runner->setAliases(['--version' => 'version']);
参数
-
array<string, string>$aliases 要替换的别名映射。
返回值
$thissetEventManager() ¶ 公共
setEventManager(Cake\Event\EventManagerInterface $eventManager): $this
获取/设置应用程序的事件管理器。
您可以使用此实例将任何新的监听器或回调注册到对象事件,或者创建您自己的事件并按需触发它们。
参数
-
Cake\Event\EventManagerInterface$eventManager 要设置的事件管理器。
返回值
$this属性详情
$_eventManager ¶ protected
Cake\Event\EventManager 的实例,该对象用于调度内部事件。
类型
Cake\Event\EventManagerInterface|null