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

來源:互聯網
上載者:User

標籤:thinkphp5

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


本文出自 “專註php 群號:414194301” 部落格,請務必保留此出處http://jingshanls.blog.51cto.com/3357095/1873737

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.