當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。