當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Controller::getUniqueId方法代碼示例

本文整理匯總了PHP中yii\console\Controller::getUniqueId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Controller::getUniqueId方法的具體用法?PHP Controller::getUniqueId怎麽用?PHP Controller::getUniqueId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\console\Controller的用法示例。


在下文中一共展示了Controller::getUniqueId方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getSubCommandHelp

 /**
  * Displays the detailed information of a command action.
  * @param Controller $controller the controller instance
  * @param string $actionID action ID
  * @throws Exception if the action does not exist
  */
 protected function getSubCommandHelp($controller, $actionID)
 {
     $action = $controller->createAction($actionID);
     if ($action === null) {
         $name = $this->ansiFormat(rtrim($controller->getUniqueId() . '/' . $actionID, '/'), Console::FG_YELLOW);
         throw new Exception("No help for unknown sub-command \"{$name}\".");
     }
     $description = $controller->getActionHelp($action);
     if ($description !== '') {
         $this->stdout("\nDESCRIPTION\n", Console::BOLD);
         $this->stdout("\n{$description}\n\n");
     }
     $this->stdout("\nUSAGE\n\n", Console::BOLD);
     $scriptName = $this->getScriptName();
     if ($action->id === $controller->defaultAction) {
         $this->stdout($scriptName . ' ' . $this->ansiFormat($controller->getUniqueId(), Console::FG_YELLOW));
     } else {
         $this->stdout($scriptName . ' ' . $this->ansiFormat($action->getUniqueId(), Console::FG_YELLOW));
     }
     $args = $controller->getActionArgsHelp($action);
     foreach ($args as $name => $arg) {
         if ($arg['required']) {
             $this->stdout(' <' . $name . '>', Console::FG_CYAN);
         } else {
             $this->stdout(' [' . $name . ']', Console::FG_CYAN);
         }
     }
     $options = $controller->getActionOptionsHelp($action);
     $options[\yii\console\Application::OPTION_APPCONFIG] = ['type' => 'string', 'default' => null, 'comment' => "custom application configuration file path.\nIf not set, default application configuration is used."];
     ksort($options);
     if (!empty($options)) {
         $this->stdout(' [...options...]', Console::FG_RED);
     }
     $this->stdout("\n\n");
     if (!empty($args)) {
         foreach ($args as $name => $arg) {
             $this->stdout($this->formatOptionHelp('- ' . $this->ansiFormat($name, Console::FG_CYAN), $arg['required'], $arg['type'], $arg['default'], $arg['comment']) . "\n\n");
         }
     }
     if (!empty($options)) {
         $this->stdout("\nOPTIONS\n\n", Console::BOLD);
         foreach ($options as $name => $option) {
             $this->stdout($this->formatOptionHelp($this->ansiFormat('--' . $name, Console::FG_RED, empty($option['required']) ? Console::FG_RED : Console::BOLD), !empty($option['required']), $option['type'], $option['default'], $option['comment']) . "\n\n");
         }
     }
 }
開發者ID:drodata,項目名稱:yii2,代碼行數:52,代碼來源:HelpController.php

示例2: getActionHelp

 /**
  * Displays the detailed information of a command action.
  * @param Controller $controller the controller instance
  * @param string $actionID action ID
  * @throws Exception if the action does not exist
  */
 protected function getActionHelp($controller, $actionID)
 {
     $action = $controller->createAction($actionID);
     if ($action === null) {
         throw new Exception(Yii::t('yii', 'No help for unknown sub-command "{command}".', ['command' => rtrim($controller->getUniqueId() . '/' . $actionID, '/')]));
     }
     if ($action instanceof InlineAction) {
         $method = new \ReflectionMethod($controller, $action->actionMethod);
     } else {
         $method = new \ReflectionMethod($action, 'run');
     }
     $tags = $this->parseComment($method->getDocComment());
     $options = $this->getOptionHelps($controller);
     if ($tags['description'] !== '') {
         $this->stdout("\nDESCRIPTION\n", Console::BOLD);
         echo "\n" . Console::renderColoredString($tags['description']) . "\n\n";
     }
     $this->stdout("\nUSAGE\n\n", Console::BOLD);
     $scriptName = $this->getScriptName();
     if ($action->id === $controller->defaultAction) {
         echo $scriptName . ' ' . $this->ansiFormat($controller->getUniqueId(), Console::FG_YELLOW);
     } else {
         echo $scriptName . ' ' . $this->ansiFormat($action->getUniqueId(), Console::FG_YELLOW);
     }
     list($required, $optional) = $this->getArgHelps($method, isset($tags['param']) ? $tags['param'] : []);
     foreach ($required as $arg => $description) {
         $this->stdout(' <' . $arg . '>', Console::FG_CYAN);
     }
     foreach ($optional as $arg => $description) {
         $this->stdout(' [' . $arg . ']', Console::FG_CYAN);
     }
     if (!empty($options)) {
         $this->stdout(' [...options...]', Console::FG_RED);
     }
     echo "\n\n";
     if (!empty($required) || !empty($optional)) {
         echo implode("\n\n", array_merge($required, $optional)) . "\n\n";
     }
     $options = $this->getOptionHelps($controller);
     if (!empty($options)) {
         $this->stdout("\nOPTIONS\n\n", Console::BOLD);
         echo implode("\n\n", $options) . "\n\n";
     }
 }
開發者ID:davidpersson,項目名稱:FrameworkBenchmarks,代碼行數:50,代碼來源:HelpController.php


注:本文中的yii\console\Controller::getUniqueId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。