当前位置: 首页>>代码示例>>PHP>>正文


PHP Command::getHelperSet方法代码示例

本文整理汇总了PHP中Illuminate\Console\Command::getHelperSet方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::getHelperSet方法的具体用法?PHP Command::getHelperSet怎么用?PHP Command::getHelperSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Console\Command的用法示例。


在下文中一共展示了Command::getHelperSet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: pick_from_list

/**
 * Present a list of choices to user, return choice
 * @param Command $command The command requesting input
 * @param array $choices List of choices
 * @param int $default Default choice (1-array size), -1 to abort
 * @param string $abort String to tag on end for aborting selection
 * @return int -1 if abort selected, otherwise one greater than $choice index
 *        (in other words, choosing $choice[0] returns 1)
 * @throws InvalidArgumentException If argument is invalid
 */
function pick_from_list(Command $command, $title, array $choices, $default = 0, $abort = null)
{
    if ($abort) {
        $choices[] = $abort;
    }
    $numChoices = count($choices);
    if (!$numChoices) {
        throw new \InvalidArgumentException("Must have at least one choice");
    }
    if ($default == -1 && empty($abort)) {
        throw new \InvalidArgumentException('Cannot use default=-1 without $abort option');
    }
    if (!between($default, -1, $numChoices)) {
        throw new \InvalidArgumentException("Invalid value, default={$default}");
    }
    $question = "Please enter a number between 1-{$numChoices}";
    if ($default > 0) {
        $question .= " (default is {$default})";
    } elseif ($default < 0) {
        $question .= " (enter to abort)";
        $default = $numChoices;
    }
    $question .= ':';
    while (1) {
        $command->line('');
        $command->info($title);
        $command->line('');
        for ($i = 0; $i < $numChoices; $i++) {
            $command->line($i + 1 . ". " . $choices[$i]);
        }
        $command->line('');
        $answer = $command->ask($question);
        if ($answer == '') {
            $answer = $default;
        }
        if (between($answer, 1, $numChoices)) {
            if ($abort and $answer == $numChoices) {
                $answer = -1;
            }
            return (int) $answer;
        }
        // Output wrong choice
        $command->line('');
        $formatter = $command->getHelperSet()->get('formatter');
        $block = $formatter->formatBlock('Invalid entry!', 'error', true);
        $command->line($block);
    }
}
开发者ID:tashakau,项目名称:getting-stuff-done-laravel-code,代码行数:58,代码来源:helpers.php


注:本文中的Illuminate\Console\Command::getHelperSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。