[李景山php]每天TP5-20161227|thinkphp5-Console.php-4

    /**
     * 获取所有的指令
     * @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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值