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


PHP ChoiceQuestion::setPrompt方法代码示例

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


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

示例1: selectGenerator

 /**
  * Returns a generator selected by the user from a multilevel console menu.
  */
 protected function selectGenerator(InputInterface $input, OutputInterface $output)
 {
     // Narrow menu tree according to the active menu items.
     $active_menu_tree = $this->menuTree;
     foreach ($this->activeMenuItems as $active_menu_item) {
         $active_menu_tree = $active_menu_tree[$active_menu_item];
     }
     // The $active_menu_tree can be either an array of child menu items or
     // the TRUE value indicating that the user reached the final menu point and
     // active menu items contain the actual command name.
     if (is_array($active_menu_tree)) {
         $subtrees = $command_names = [];
         // We build $choices as an associative array to be able to find
         // later menu items by respective labels.
         foreach ($active_menu_tree as $menu_item => $subtree) {
             $menu_item_label = $this->createMenuItemLabel($menu_item, is_array($subtree));
             if (is_array($subtree)) {
                 $subtrees[$menu_item] = $menu_item_label;
             } else {
                 $command_names[$menu_item] = $menu_item_label;
             }
         }
         asort($subtrees);
         asort($command_names);
         // Generally the choices array consists of the following parts:
         // - Reference to the parent menu level.
         // - Sorted list of nested menu levels.
         // - Sorted list of commands.
         $choices = ['..' => '..'] + $subtrees + $command_names;
         $question = new ChoiceQuestion('<title>Select generator:</title>', array_values($choices));
         $question->setPrompt('  >>> ');
         $answer_label = $this->getHelper('question')->ask($input, $output, $question);
         $answer = array_search($answer_label, $choices);
         if (!$answer) {
             throw new \UnexpectedValueException(sprintf('"%s" menu item was not found', $answer_label));
         }
         if ($answer == '..') {
             // Exit the application if the user choices zero key
             // on the top menu level.
             if (count($this->activeMenuItems) == 0) {
                 return NULL;
             }
             // Set the menu one level higher.
             array_pop($this->activeMenuItems);
         } else {
             // Set the menu one level deeper.
             $this->activeMenuItems[] = $answer;
         }
         return $this->selectGenerator($input, $output);
     } else {
         return implode(':', $this->activeMenuItems);
     }
 }
开发者ID:chi-teck,项目名称:drupal-code-generator,代码行数:56,代码来源:Navigation.php


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