/**

* 执行指令

* @param Input  $input

* @param Output $output

* @return int

*/

public function doRun(Input $input, Output $output)

{// 真正 运行 函数开始

if (true === $input->hasParameterOption(['--version', '-V'])) {

$output->writeln($this->getLongVersion());// 写出版本信息

return 0;// 返回 0

}// 如果有 版本

$name = $this->getCommandName($input);// 获取命令 名字

if (true === $input->hasParameterOption(['--help', '-h'])) {// 如果是帮助信息

if (!$name) {// 明显 跟 linux 靠近了

$name  = 'help';// help

$input = new Input(['help']);// 返回帮助信息

} else {

$this->wantHelps = true;// 把想要帮助的信息 设置为1

}

}

if (!$name) {// 如果没有获取到相应的命令

$name  = $this->defaultCommand;// 设置默认的命令

$input = new Input([$this->defaultCommand]);// 输入信息为默认命令

}

$command = $this->find($name);// 查找命令 根据 名字 ,名字,其实就是个索引 主键 id

$exitCode = $this->doRunCommand($command, $input, $output);// 执行 命令 带着 输入 跟输出

return $exitCode;// 返回执行后的结果

}

/**

* 设置输入参数定义

* @param InputDefinition $definition

*/

public function setDefinition(InputDefinition $definition)

{

$this->definition = $definition;

}// 设置输入参数定义

/**

* 获取输入参数定义

* @return InputDefinition The InputDefinition instance

*/

public function getDefinition()

{

return $this->definition;

}// 获取输入 参数 定义

/**

* Gets the help message.

* @return string A help message.

*/

public function getHelp()

{

return $this->getLongVersion();

}// 获取帮助信息 就是 获取版本信息

/**

* 是否捕获异常

* @param bool $boolean

* @api

*/

public function setCatchExceptions($boolean)

{

$this->catchExceptions = (bool)$boolean;

}// 设置 是否 捕获异常,强制  转换 一些 数据

/**

* 是否自动退出

* @param bool $boolean

* @api

*/

public function setAutoExit($boolean)

{

$this->autoExit = (bool)$boolean;

}// 自动退出

/**

* 获取名称

* @return string

*/

public function getName()

{

return $this->name;

}// 返回名字

/**

* 设置名称

* @param string $name

*/

public function setName($name)

{

$this->name = $name;

}// 设置名字

/**

* 获取版本

* @return string

* @api

*/

public function getVersion()

{

return $this->version;

}// 设置版本

/**

* 设置版本

* @param string $version

*/

public function setVersion($version)

{

$this->version = $version;

}//设置版本

/**

* 获取完整的版本号

* @return string

*/

public function getLongVersion()

{

if ('UNKNOWN' !== $this->getName() && 'UNKNOWN' !== $this->getVersion()) {

return sprintf('%s version %s', $this->getName(), $this->getVersion());

}

return 'Console Tool';// 信息 显示 控制

}// 获取版本号

/**

* 注册一个指令

* @param string $name

* @return Command

*/

public function register($name)

{

return $this->add(new Command($name));

}// 注册 指令

/**

* 添加指令

* @param Command[] $commands

*/

public function addCommands(array $commands)

{

foreach ($commands as $command) {

$this->add($command);

}

}// 添加 指令

/**

* 添加一个指令

* @param Command $command

* @return Command

*/

public function add(Command $command)

{

$command->setConsole($this);// 设置命令 控制台

if (!$command->isEnabled()) {

$command->setConsole(null);

return null;

}// 允许设计,进行设置

if (null === $command->getDefinition()) {

throw new \LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));

}// 获取默认 参数 定义

$this->commands[$command->getName()] = $command;// 命令 设置

foreach ($command->getAliases() as $alias) {

$this->commands[$alias] = $command;

}// 循环 设置 别名

return $command;// 返回 数据

}

/**

* 获取指令

* @param string $name 指令名称

* @return Command

* @throws \InvalidArgumentException

*/

public function get($name)

{// 获取 指令

if (!isset($this->commands[$name])) {

throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));

}// 抛出 设置 异常

$command = $this->commands[$name];// 设置命令

if ($this->wantHelps) {

$this->wantHelps = false;

/** @var HelpCommand $helpCommand */

$helpCommand = $this->get('help');

$helpCommand->setCommand($command);

return $helpCommand;

}// 一些 帮助的命令

return $command;// 返回命令

}

php tp5 parent,[李景山php]每天TP5-20161225|thinkphp5-Console.php-2相关推荐

  1. php tp5.3,[李景山php]每天TP5-20161226|thinkphp5-Console.php-3

    /** * 某个指令是否存在 * @param string $name 指令名称 * @return bool */ public function has($name) { return isse ...

  2. tp5路径怎样去掉index.php,tp5如何隐藏index.php文件

    tp5隐藏index.php文件的方法:首先在文件入口的同级目录下添加".htaccess"文件:然后配置内容为"RewriteCond %{REQUEST_FILENA ...

  3. tp5 if 如果有html判断,tp5条件判断,in,notin,between,if等

    一.比较标签如: {比较标签 name="变量" value="值"} 内容 {/比较标签} {eq name="name" value=& ...

  4. tp5 php里如何打印变量,TP5系统变量输出

    1.系统变量 在index.html文件中: 我是index控制器index操作模板文件 server.http_host: {$Think.server.http_host} cookie.site ...

  5. tp5.1添加定时器任务linux,TP5 用cron实现linux定时任务

    TP5 用cron实现linux定时任务 1) tp5的控制器内容: namespace app\test\controller; use think\Controller; use think\fa ...

  6. tp5 怎么跳转php页面,tp5页面跳转重定向

    三.页面跳转 1.方法存在的文件路径 TP5\thinkphp\library\traits\controller\Jump.php 成功跳转$this->success(); 失败跳转$thi ...

  7. tp5多图上传php,TP5框架实现上传多张图片的方法分析

    本文实例讲述了tp5框架实现上传多张图片的方法.分享给大家供大家参考,具体如下: 1.效果图(每点击一次'添加选项',就会有一个新的 file 框来添加新的图片) 2.view 添加 $(" ...

  8. [李景山php]每天TP5-20161225|thinkphp5-Console.php-2

    /*** 执行指令* @param Input $input* @param Output $output* @return int*/ public function doRun(Input $in ...

  9. [李景山php]每天TP5-20170131|thinkphp5-Request.php-3

    /*** 获取当前URL 不含QUERY_STRING* @access public* @param string $url URL地址* @return string*/ public funct ...

最新文章

  1. 用Machin公式计算圆周率的源程序
  2. js 删除数组几种方法
  3. 开发日记-20190407
  4. 猎鹰spacex_SpaceX:简单,美观的界面是未来
  5. 【开源项目】EasyCmd命令图形化软件
  6. POJ1149 最大流(Isap)
  7. 【前沿】PurdueUCLA提出梯度Boosting网络,效果远好于XGBoost模型!
  8. kubernetes v1.8.8中 RBAC DENY 解决办法
  9. 统计计算机考试题,销售统计表计算机windows一级最新考试试题
  10. 【线性代数笔记】秩为1的矩阵的性质
  11. C4D怎么快速建模桌布? c4d创建桌布的教程
  12. SNIP算法详解(极端尺寸目标检测)
  13. HTTP/HTTPS账号密码获取
  14. 使用RSD对高分1号卫星数据进行批量大气校正
  15. 人工智能数学基础---定积分5:使用分部积分法计算定积分
  16. Wake-on-LAN(远端唤醒) 原理及实现
  17. 实习 | QQ音乐(深圳)娱乐营销实习生
  18. 机器学习 刀光剑影 之屠龙刀
  19. 最新炼数成金实战Java高并发程序设计+完整课件
  20. HTML旅游网页设计制作 DW旅游网站官网滚动网页 DIV旅游风景介绍网页设计与实现...

热门文章

  1. 中国 GitHub 开发者数量年增长 37%,为全球最快
  2. 你根本不需要去追求“完美”的软件!
  3. 春眠不觉晓,SQL 知多少?| 原力计划
  4. 装机量 2 亿,这款国产物联网操作系统为何是“小而美”?
  5. 云原生与数据中台,企业数字化转型的“正确打开方式”
  6. 百行代码解读阿里 AloT 芯片平台无剑 100!
  7. 谷歌称已实现量子霸权;iOS 捷径功能被诉侵权;Chrome 78 Beta 发布 | 极客头条
  8. 程序员如何从初中级历练为高级开发者?
  9. 马云等第一代互联网创始人退休,BAT 谁来接手?| 畅言
  10. 华为在剑桥建芯片厂;小米公布出货量反驳调研机构; 中移动否认限制号 | 极客头条...