/*** 执行指令* @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('<info>%s</info> version <comment>%s</comment>', $this->getName(), $this->getVersion());}return '<info>Console Tool</info>';// 信息 显示 控制
}// 获取版本号/*** 注册一个指令* @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;// 返回命令
}

转载于:https://blog.51cto.com/jingshanls/1873737

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

  1. php tp5 parent,[李景山php]每天TP5-20161225|thinkphp5-Console.php-2

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

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

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

  3. 【TP5】Thinkphp5初体验1

    听说thinkphp5要正式发布了,对于这个蛮不错的实用开发工具,我觉着还是有必要继续跟进学习使用使用的,翻了翻资料找到了这个还未完善的文档,不过,够了,先来个简单开始吧,本文用的是dev-maste ...

  4. tp5缺少start.php,【TP5】Thinkphp5初体验1

    听说thinkphp5要正式发布了,对于这个蛮不错的实用开发工具,我觉着还是有必要继续跟进学习使用使用的,翻了翻资料找到了这个还未完善的文档,不过,够了,先来个简单开始吧,本文用的是dev-maste ...

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

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

  6. [李景山php]每天TP5-20170111|thinkphp5-Model.php-4

    /*** 设置需要追加的输出属性* @access public* @param array $append 属性列表* @return $this*/ public function append( ...

  7. [李景山php]每天TP5-20170125|thinkphp5-Process.php-7

    /*** 获取输入* @return null|string*/public function getInput(){return $this->input;}// 获取输入信息/*** 设置输 ...

  8. [李景山php]每天TP5-20170114|thinkphp5-Model.php-7

    /*** 删除记录* @access public* @param mixed $data 主键列表 支持闭包查询条件* @return integer 成功删除的记录数*/ public stati ...

  9. [李景山php]每天TP5-20170110|thinkphp5-Model.php-3

    /*** 自动写入时间戳* @access public* @param string $name 时间戳字段* @return mixed*/ protected function autoWrit ...

最新文章

  1. 树链剖分 ---- 2021杭电多校 1002 I love tree[详解]
  2. 算法之道:形而之上谓之道
  3. git pull 问题“error: Your local changes to the following files would be overwritten by merge”
  4. 同一事务多次加for_Synchronized锁在Spring事务管理下,为啥还线程不安全?
  5. 捕捉不可控iframe的close事件_湖南大学王建锋团队:光/湿驱动的超快可逆可控致动器...
  6. WebBrowser内存泄露
  7. git 操作常用指令
  8. [AGC016B]Colorful Hats
  9. 化工原理少学时答案解析_初中科学电磁铁的构造和原理每日一练含答案解析
  10. 【雷军】给程序员的五点建议--如何成为编程高手并以此创业
  11. c++远征之模板篇——标准模板库(STL)
  12. PHP留言并展示_利用PHP实现简单留言板
  13. python end of statement_17个新手常见Python运行时错误
  14. python函数模块关键代码_从零开始学Python(六):函数,模块和类的使用
  15. 全国程序员工资最新统计来了,平均 14,542 元!
  16. 非线性方程求根算法的C++实现
  17. linux u盘 修复工具,如何在Linux终端中修复U盘驱动器问题
  18. 【论文笔记】ASNet:基于生成对抗网络(GAN)的无监督单模和多模配准网络(范敬凡老师)
  19. idea设置前进、后退快捷键
  20. golang 实现HTTP代理和反向代理

热门文章

  1. CSS3图片跳动效果
  2. Mysql数据库常用分库和分表方式
  3. Docker入门与实战
  4. scrapy使用crawlspider
  5. VMWare 修改虚拟机的swap文件
  6. 【在线集成开发环境】Eclipse Che简单上手体验
  7. laravel控制器方法中,用函数作为变量进行传递时的处理方法
  8. 美国人与欧洲人为什么都吃转基因食品?
  9. 迭代器——STL关键所在
  10. iOS 开发----Xcode 因为证书问题经常报的那些错