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


PHP XPClass::getComment方法代码示例

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


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

示例1: showUsage

 /**
  * Show usage
  *
  * @param   lang.XPClass class
  */
 public static function showUsage(XPClass $class)
 {
     // Description
     if (null !== ($comment = $class->getComment())) {
         self::$err->writeLine(self::textOf($comment));
         self::$err->writeLine(str_repeat('=', 72));
     }
     $extra = $details = $positional = [];
     foreach ($class->getMethods() as $method) {
         if (!$method->hasAnnotation('arg')) {
             continue;
         }
         $arg = $method->getAnnotation('arg');
         $name = strtolower(preg_replace('/^set/', '', $method->getName()));
         $comment = self::textOf($method->getComment());
         if (0 == $method->numParameters()) {
             $optional = true;
         } else {
             list($first, ) = $method->getParameters();
             $optional = $first->isOptional();
         }
         if (isset($arg['position'])) {
             $details['#' . ($arg['position'] + 1)] = $comment;
             $positional[$arg['position']] = $name;
         } else {
             if (isset($arg['name'])) {
                 $details['--' . $arg['name'] . ' | -' . (isset($arg['short']) ? $arg['short'] : $arg['name'][0])] = $comment;
                 $extra[$arg['name']] = $optional;
             } else {
                 $details['--' . $name . ' | -' . (isset($arg['short']) ? $arg['short'] : $name[0])] = $comment;
                 $extra[$name] = $optional;
             }
         }
     }
     // Usage
     asort($positional);
     self::$err->write('Usage: $ xpcli ', $class->getName(), ' ');
     foreach ($positional as $name) {
         self::$err->write('<', $name, '> ');
     }
     foreach ($extra as $name => $optional) {
         self::$err->write($optional ? '[' : '', '--', $name, $optional ? '] ' : ' ');
     }
     self::$err->writeLine();
     // Argument details
     self::$err->writeLine('Arguments:');
     foreach ($details as $which => $comment) {
         self::$err->writeLine('* ', $which, "\n  ", str_replace("\n", "\n  ", $comment), "\n");
     }
 }
开发者ID:johannes85,项目名称:core,代码行数:55,代码来源:Runner.class.php

示例2: commandUsage

 /**
  * Shows usage
  *
  * @param  lang.XPClass $class
  * @return void
  */
 protected function commandUsage(XPClass $class)
 {
     $comment = $class->getComment();
     if ('' === (string) $comment) {
         $markdown = '# ' . $class->getSimpleName() . "\n\n";
         $text = '';
     } else {
         @(list($headline, $text) = explode("\n", $comment, 2));
         $markdown = '# ' . ltrim($headline, ' #') . "\n\n";
     }
     $markdown .= "- Usage\n  ```sh\n\$ xp cmd " . Commands::nameOf($class);
     $extra = $details = $positional = [];
     foreach ($class->getMethods() as $method) {
         if (!$method->hasAnnotation('arg')) {
             continue;
         }
         $arg = $method->getAnnotation('arg');
         $name = strtolower(preg_replace('/^set/', '', $method->getName()));
         $optional = 0 === $method->numParameters() || $method->getParameters()[0]->isOptional();
         $comment = $method->getComment();
         if (isset($arg['position'])) {
             $details[$name] = [$comment, null];
             $positional[$arg['position']] = $name;
         } else {
             if (isset($arg['name'])) {
                 $details['--' . $arg['name']] = [$comment, isset($arg['short']) ? $arg['short'] : $arg['name'][0]];
                 $extra[$arg['name']] = $optional;
             } else {
                 $details['--' . $name] = [$comment, isset($arg['short']) ? $arg['short'] : $name[0]];
                 $extra[$name] = $optional;
             }
         }
     }
     // Usage
     asort($positional);
     foreach ($positional as $name) {
         $markdown .= ' ' . $name;
     }
     foreach ($extra as $name => $optional) {
         $markdown .= ' ' . (($optional ? '[' : '') . '--' . $name . ($optional ? '] ' : ' '));
     }
     $markdown .= "\n  ```\n";
     // Argument details
     foreach ($details as $which => $detail) {
         $markdown .= sprintf("  **%s**: %s%s\n\n", $which, str_replace("\n", "\n  ", $detail[0]), $detail[1] ? ' *(also: -' . $detail[1] . ')*' : '');
     }
     Help::render(self::$err, substr($markdown, 0, -1) . $text, $class->getClassLoader());
 }
开发者ID:xp-framework,项目名称:command,代码行数:54,代码来源:CmdRunner.class.php

示例3: usage

 /**
  * Displays usage
  *
  * @param   lang.XPClass class
  * @return  int
  */
 protected static function usage(\lang\XPClass $class)
 {
     \util\cmd\Console::$err->writeLine(self::textOf($class->getComment()));
     return 1;
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:11,代码来源:Runner.class.php


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