コード例 #1
0
ファイル: DocComment.php プロジェクト: solve/solve
 /**
  * @param $source
  * @return DocComment
  */
 public static function parseFromString($source)
 {
     $comment = new DocComment();
     if (substr($source, 0, 3) !== '/**') {
         return $comment;
     }
     $source = explode("\n", preg_replace(array('~(^\\s*/\\*\\*\\s*|\\s*\\*/\\s*$)~', '~^\\h*\\*?\\h?~m', '~\\h+$~'), '', $source));
     $commentDescription = '';
     $isDescription = true;
     foreach ($source as $line) {
         if ($line && $line[0] == '@') {
             $isDescription = false;
             $nameEndIndex = strpos($line, ' ');
             $description = '';
             if ($nameEndIndex !== false) {
                 $name = mb_substr($line, 1, $nameEndIndex - 1);
                 $description = trim(mb_substr($line, $nameEndIndex));
             } else {
                 $name = mb_substr($line, 1);
             }
             $comment->addAnnotation($name, $description);
         } else {
             if ($isDescription) {
                 $commentDescription .= $line . "\n";
             }
         }
     }
     $comment->setDescription(trim($commentDescription));
     return $comment;
 }
コード例 #2
0
ファイル: IndexController.php プロジェクト: solve/solve
 public function defaultAction()
 {
     $this->writeln('Available commands:');
     $controllers = array('SolveConsole\\Controllers\\DbController', 'SolveConsole\\Controllers\\GenController');
     $commandsList = '';
     foreach ($controllers as $controllerName) {
         $r = new \ReflectionClass($controllerName);
         $name = Inflector::underscore(substr($r->getShortName(), 0, -10));
         $help = DocComment::parseFromString($r->getDocComment())->getAnnotationsAsString('help');
         $commandsList .= '  <bold>' . $name . "</bold>\t" . $help . "\n";
     }
     $this->writeln($commandsList);
 }
コード例 #3
0
ファイル: ConsoleController.php プロジェクト: solve/solve
 public function defaultAction()
 {
     $methods = $this->_reflect->getMethods(\ReflectionMethod::IS_PUBLIC);
     $methodsList = '';
     $skippedMethods = array('_preAction', '_postAction', 'defaultAction');
     foreach ($methods as $method) {
         if (!in_array($method->getName(), $skippedMethods) && substr($method->getName(), -6) === 'Action') {
             $commandMethod = str_replace('_', '-', Inflector::underscore(substr($method->getName(), 0, -6)));
             $doc = DocComment::parseFromString($method->getDocComment());
             $optional = $doc->getAnnotationsAsString('optional');
             $methodsList .= "  <bold>" . $commandMethod . (strlen($commandMethod) < 16 ? str_repeat(' ', 12 - strlen($commandMethod)) : '') . "\t</bold>" . $doc->getDescription() . ($optional ? "\n\t\t" . $optional : "") . "\n";
         }
     }
     if (!empty($methodsList)) {
         $this->writeln('Here are methods of ' . $this->_command . ":");
         $this->writeln($methodsList);
     } else {
         $this->writeln('Command ' . $this->_commandColor . ' does not have any methods');
     }
 }