/** * 获取所有的指令 * @param string $namespace 命名空间 * @return Command[] * @api */ public function all($namespace = null) {// 获取全部指令 if (null === $namespace) { return $this->commands; }// 为空 就获取全部的指令 $commands = [];// 命令仓库 foreach ($this->commands as $name => $command) {// 遍历搜索仓库 if ($this->extractNamespace($name, substr_count($namespace, ':') + 1) === $namespace) {// 如果存在这个命令 $commands[$name] = $command;// 装入这个 仓库 } } return $commands;// 返回数据 } /** * 获取可能的指令名 * @param array $names * @return array */ public static function getAbbreviations($names) {// 获取 可能的 指令名 $abbrevs = [];//仓库 foreach ($names as $name) {// 遍历循环 for ($len = strlen($name); $len > 0; --$len) {// 不断递减的 指令名称 $abbrev = substr($name, 0, $len); $abbrevs[$abbrev][] = $name;// 更细致的 指令名称 } } return $abbrevs;// 返回数据集合 } /** * 配置基于用户的参数和选项的输入和输出实例。 * @param Input $input 输入实例 * @param Output $output 输出实例 */ protected function configureIO(Input $input, Output $output) {// 配置基于用户的参数和选项的输入和输出实例 // Input 是个 class Output 也是个class if (true === $input->hasParameterOption(['--ansi'])) { $output->setDecorated(true);// 设置对应的 选项 } elseif (true === $input->hasParameterOption(['--no-ansi'])) { $output->setDecorated(false);// 设置对应的选项 } if (true === $input->hasParameterOption(['--no-interaction', '-n'])) { $input->setInteractive(false); }// 选项设置 if (true === $input->hasParameterOption(['--quiet', '-q'])) { $output->setVerbosity(Output::VERBOSITY_QUIET);// 选项设置 } else { if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) { $output->setVerbosity(Output::VERBOSITY_DEBUG); } elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) { $output->setVerbosity(Output::VERBOSITY_VERY_VERBOSE); } elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) { $output->setVerbosity(Output::VERBOSITY_VERBOSE); } } }// 根据输入的选项 设置 输出的 选项 /** * 执行指令 * @param Command $command 指令实例 * @param Input $input 输入实例 * @param Output $output 输出实例 * @return int * @throws \Exception */ protected function doRunCommand(Command $command, Input $input, Output $output) { return $command->run($input, $output);// 已知输入输出 ,运行实例 }// 执行指令 /** * 获取指令的基础名称 * @param Input $input * @return string */ protected function getCommandName(Input $input) { return $input->getFirstArgument(); }// 获取指令的基础名称 /** * 获取默认输入定义 * @return InputDefinition */ protected function getDefaultInputDefinition() {// 获取 默认 输入定义 return new InputDefinition([ new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'), new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this console version'), new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'), new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'), new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'), new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'), new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'), ]); }// 对应的 key 及 value
[李景山php]每天TP5-20161227|thinkphp5-Console.php-4
原创
©著作权归作者所有:来自51CTO博客作者lijingsan1的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章