示例#1
0
<?php

require 'lang.base.php';
uses('text.doclet.RootDoc', 'util.cmd.Console');
$P = new ParamString();
if (!$P->exists('doclet')) {
    die('Parameter "--doclet" is required!');
} else {
    $doclet_name = $P->value('doclet');
    try {
        $Class = XPClass::forName($doclet_name)->newInstance();
        if (!is('Doclet', $Instance)) {
            throw new IllegalArgumentException('Given classname is not a "Doclet" class!');
        }
    } catch (Exception $e) {
        die($e->toString());
    }
    // remove '--doclet' argument and pass the rest to RootDoc
    while (list($key, $val) = each($P->list)) {
        if (0 == strncmp('--doclet', $val, 7)) {
            continue;
        }
        $list[$key] = $val;
    }
    RootDoc::start($Instance, new ParamString($list));
}
示例#2
0
 /**
  * Runner method
  *
  */
 public static function main(array $args)
 {
     // Show command usage if invoked without arguments
     if (!$args) {
         exit(self::usage(XPClass::forName(xp::nameOf(__CLASS__))));
     }
     $root = new RootDoc();
     for ($i = 0, $s = sizeof($args); $i < $s; $i++) {
         if ('-sp' === $args[$i]) {
             $root->setSourcePath(explode(PATH_SEPARATOR, $args[++$i]));
         } else {
             if ('-cp' === $args[$i]) {
                 foreach (explode(PATH_SEPARATOR, $args[++$i]) as $element) {
                     $root->addSourcePath(ClassLoader::registerPath($element, NULL)->path);
                 }
             } else {
                 try {
                     $class = XPClass::forName($args[$i]);
                 } catch (ClassNotFoundException $e) {
                     Console::$err->writeLine('*** ', $e->getMessage());
                     exit(2);
                 }
                 if (!$class->isSubclassOf('text.doclet.Doclet')) {
                     Console::$err->writeLine('*** ', $class, ' is not a doclet');
                     exit(2);
                 }
                 $doclet = $class->newInstance();
                 $params = new ParamString(array_slice($args, $i));
                 // Show doclet usage if the command line contains "-?" (at any point).
                 if ($params->exists('help', '?')) {
                     self::usage($class);
                     if ($valid = $doclet->validOptions()) {
                         Console::$err->writeLine();
                         Console::$err->writeLine('Options:');
                         foreach ($valid as $name => $value) {
                             Console::$err->writeLine('  * --', $name, OPTION_ONLY == $value ? '' : '=<value>');
                         }
                     }
                     exit(3);
                 }
                 $root->start($doclet, $params);
                 exit(0);
             }
         }
     }
     Console::$err->writeLine('*** No doclet classname given');
     exit(1);
 }