コード例 #1
0
 /**
  * Run Doclet
  *
  */
 public function start($root)
 {
     // test hasNext()?
     while ($root->classes->hasNext()) {
         $ClassDoc = $root->classes->next();
         $classnames[] = $ClassDoc->qualifiedName();
     }
     // generate diagram via DiaMarshaller
     $Dia = DiaMarshaller::marshal($classnames, $root->option('recurse', 0), $root->option('depend', FALSE));
     // default destination is the current directory
     $filename = $root->option('directory', '.') . DIRECTORY_SEPARATOR;
     if ($root->option('diagram', FALSE)) {
         $filename .= $root->option('diagram');
     } else {
         $filename .= $ClassDoc->qualifiedName() . '.dia';
     }
     // save diagram to file
     $Dia->saveTo($filename, $root->option('gzipped', FALSE));
 }
コード例 #2
0
ファイル: update.php プロジェクト: Gamepay/xp-contrib
     $depend = $P->value('depend');
 }
 $classes = explode(',', $P->value('classes'));
 $file = $P->value('diagram');
 // if file does not exist: generate diagram
 if (!file_exists($file)) {
     Console::writeLine('File not found! Generating new diagram...');
     if (!isset($recurse)) {
         $recurse = 2;
         Console::writeLine('Using default "recurse=2"...');
     }
     if (!isset($depend)) {
         $depend = TRUE;
         Console::writeLine('Using default "depend=TRUE"...');
     }
     $Dia = DiaMarshaller::marshal($classes, $recurse, $depend);
     $Dia->saveTo($file, FALSE);
 } else {
     // else: update diagram
     Console::writeLine('Diagram file found: updating classes...');
     // initialize objects
     try {
         // Visitor checks if the given classes exist
         $Visitor = new UpdateVisitor($classes, TRUE, TRUE);
     } catch (Exception $e) {
         $e->printStackTrace();
         exit(-1);
     }
     Console::writeLine('Parsing XML diagram file...');
     try {
         $Dia = DiaUnmarshaller::unmarshal($file);
コード例 #3
0
 /**
  * Turns any number of given classnames into a 'dia' diagram
  *
  * @param   array classnames An array containing fully qualified class names
  * @param   int recurse default 0 How many levels of recursion
  * @param   bool depend default FALSE Include dependencies
  * @return  org.dia.DiaDiagram
  */
 public static function marshal($classnames, $recurse = 0, $depend = FALSE)
 {
     $I = DiaMarshaller::getInstance();
     // initialize RootDoc
     $I->_root = new RootDoc();
     // initialize DiaDiagram
     $I->_dia = new DiaDiagram();
     $I->_dia->initialize();
     $Layers = $I->_dia->getChildByType('DiaLayer');
     $I->_layer = $Layers[0];
     /*
     method 1:
     - loop over array of classnames
     - add classnames during recursion...
     
     method 2:
     - loop over array of classnames
     - recurse directly
     */
     // initialize variables
     $I->_classes = array();
     $I->_classnames = $classnames;
     reset($I->_classnames);
     // reset array
     // process given classes
     while ($name = current($I->_classnames)) {
         $I->_recurse($name, $recurse, $depend);
         next($I->_classnames);
     }
     /*foreach (array_values($I->_classnames) as $name) {
         //if (isset($this->_classes[$name])) continue; // already processed
         $I->_recurse($name, $recurse, $depend);
       }*/
     Console::writeLine('Classes: ' . xp::stringOf(array_keys($I->_classes)));
     Console::writeLine('Dependencies: ' . xp::stringOf($I->_deps));
     Console::writeLine('Implementations: ' . xp::stringOf($I->_imps));
     Console::writeLine('Generalizations: ' . xp::stringOf($I->_gens));
     // generate and add classes to DiaDiagram
     foreach (array_keys($I->_classes) as $classname) {
         try {
             $Dia_class = $I->_genClass($I->_classes[$classname]);
         } catch (IllegalArgumentException $e) {
             $e->printStackTrace();
             exit(-1);
         }
         // save dia object-id by classname
         $I->_class_ids[$classname] = $Dia_class->getId();
         // add to DiaDiagram
         $I->_layer->addObject($Dia_class);
     }
     //Console::writeLine('IDs: '.xp::stringOf($I->_class_ids));
     // generate and add dependencies
     foreach (array_keys($I->_deps) as $from) {
         foreach ($I->_deps[$from] as $to) {
             // skip if there exists also a generalization or implementation
             if ($I->_gens[$from] === $to or in_array($to, $I->_imps[$from])) {
                 // Console::writeLine("Skipping dependency: $from -> $to");
                 continue;
             }
             // add to DiaDiagram
             $I->_layer->addObject($I->_genDependency($from, $to));
         }
     }
     // generate and add implementations
     foreach (array_keys($I->_imps) as $from) {
         foreach ($I->_imps[$from] as $to) {
             // skip if there exists also a generalization?
             if (in_array($to, $I->_gens[$from])) {
                 // Console::writeLine("Skipping implementation: $from -> $to");
                 continue;
             }
             // add to DiaDiagram
             $I->_layer->addObject($I->_genImplemenation($from, $to));
         }
     }
     // generate and add generalizations
     foreach (array_keys($I->_gens) as $from) {
         $to = $I->_gens[$from];
         // Console::writeLine("Gen: $from -> $to...");
         // add to DiaDiagram
         $I->_layer->addObject($I->_genGeneralization($from, $to));
     }
     return $I->_dia;
 }