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

/**

* 执行指令

* @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;// 返回命令

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值