Webmozart\Console\Api\Command\Command::hasAliases PHP Method

hasAliases() public method

Returns whether the command has aliases.
public hasAliases ( ) : boolean
return boolean Returns `true` if the command has aliases and `false` otherwise.
    public function hasAliases()
    {
        return count($this->aliases) > 0;
    }

Usage Example

コード例 #1
0
ファイル: CommandHelp.php プロジェクト: webmozart/console
 /**
  * Renders the "Usage" section.
  *
  * @param BlockLayout $layout  The layout.
  * @param Command     $command The command to render.
  */
 protected function renderUsage(BlockLayout $layout, Command $command)
 {
     $formatsToPrint = array();
     // Start with the default commands
     if ($command->hasDefaultSubCommands()) {
         // If the command has default commands, print them
         foreach ($command->getDefaultSubCommands() as $subCommand) {
             // The name of the sub command is only optional (i.e. printed
             // wrapped in brackets: "[sub]") if the command is not
             // anonymous
             $nameOptional = !$subCommand->getConfig()->isAnonymous();
             $formatsToPrint[] = array($subCommand->getArgsFormat(), $nameOptional);
         }
     } else {
         // Otherwise print the command's usage itself
         $formatsToPrint[] = array($command->getArgsFormat(), false);
     }
     // Add remaining sub-commands
     foreach ($command->getSubCommands() as $subCommand) {
         // Don't duplicate default commands
         if (!$subCommand->getConfig()->isDefault()) {
             $formatsToPrint[$subCommand->getName()] = array($subCommand->getArgsFormat(), false);
         }
     }
     $appName = $command->getApplication()->getConfig()->getName();
     $prefix = count($formatsToPrint) > 1 ? '    ' : '';
     $layout->add(new Paragraph('<b>USAGE</b>'));
     $layout->beginBlock();
     foreach ($formatsToPrint as $vars) {
         $this->renderSynopsis($layout, $vars[0], $appName, $prefix, $vars[1]);
         $prefix = 'or: ';
     }
     if ($command->hasAliases()) {
         $layout->add(new EmptyLine());
         $this->renderAliases($layout, $command->getAliases());
     }
     $layout->endBlock();
     $layout->add(new EmptyLine());
 }