home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / core / Phpdoc.php next >
Encoding:
PHP Script  |  2001-02-18  |  7.3 KB  |  240 lines

  1. <?php
  2. /**
  3. * Coordinates several Phpdoc Object to parse and render source files.
  4. * @access   public
  5. * @version  $Id: Phpdoc.php,v 1.5 2001/02/18 15:29:29 uw Exp $
  6. */
  7. class Phpdoc extends PhpdocSetupHandler {
  8.  
  9.     /**
  10.     * Result from the indexer
  11.     *
  12.     * @var  array
  13.     * @see  render()
  14.     */
  15.     var $indexer_result = array();
  16.  
  17.     /**
  18.     * Print status messages
  19.     */
  20.     var $flag_output = true;
  21.  
  22.     /**
  23.     * Calls the command line handler if necessary.
  24.     *
  25.     * WARNING: Does not work
  26.     *
  27.     * @global array $argc, string $PHP_SELF
  28.     */
  29.     function Phpdoc() {
  30.         global $argc, $PHP_SELF;
  31.  
  32.         $this->target = $PHP_SELF . "apidoc/";
  33.  
  34.         if ($argc > 1) 
  35.             $this->handleArgv();
  36.  
  37.     } // end constructor
  38.  
  39.     /**
  40.     * Starts the parser. 
  41.     *
  42.     * @return   bool        $ok
  43.     * @throws   PhpdocError
  44.     * @access   public
  45.     */
  46.     function parse() {
  47.  
  48.         $this->warn = new PhpdocWarning;
  49.  
  50.         $errors = $this->checkStatus();
  51.         if (0 != count($errors)) {
  52.  
  53.             reset($errors);
  54.             while (list($k, $error)=each($errors))
  55.                 $this->err[] = new PhpdocError($error["msg"]."Errno = ".$error["errno"], 9, __FILE__, __LINE__);
  56.  
  57.             return false;
  58.         }
  59.  
  60.         $this->outl("Parser starts...");
  61.  
  62.         // create some objects
  63.         $fileHandler    = new PhpdocFileHandler;
  64.         $parser         = new PhpdocParser(true);
  65.         $classAnalyser  = new PhpdocClassAnalyser;
  66.         $moduleAnalyser = new PhpdocModuleAnalyser;
  67.  
  68.         $indexer    = new PhpdocIndexer;                
  69.  
  70.         $classExporter  = new PhpdocXMLClassExporter();
  71.         $classExporter->setPath($this->target);
  72.  
  73.         $moduleExporter = new PhpdocXMLModuleExporter();
  74.         $moduleExporter->setPath($this->target);
  75.  
  76.         $indexExporter = new PhpdocXMLIndexExporter();
  77.         $indexExporter->setPath($this->target);
  78.  
  79.         $warningExporter = new PhpdocXMLWarningExporter();
  80.         $warningExporter->setPath($this->target);
  81.  
  82.         // This will change one fine day! 
  83.         $parser->warn         = $this->warn;
  84.         $classAnalyser->warn  = $this->warn;
  85.         $moduleAnalyser->warn = $this->warn;
  86.         $classExporter->warn  = $this->warn;
  87.         $moduleExporter->warn = $this->warn;
  88.         $indexer->warn        = $this->warn; 
  89.  
  90.         $sourcefiles = $fileHandler->getFilesInDirectory($this->sourceDirectory, $this->sourceFileSuffix);
  91.         $parser->setPhpSourcecodeFiles($fileHandler->get($sourcefiles));
  92.  
  93.         $this->outl("... preparse to find modulegroups and classtrees.");
  94.         $parser->preparse();
  95.  
  96.         $this->outl("... parsing classes.");
  97.         while ($classtree = $parser->getClassTree()) {
  98.  
  99.             $classAnalyser->setClasses( $classtree, $parser->current_baseclass );
  100.             $classAnalyser->analyse();
  101.  
  102.             while ($class = $classAnalyser->getClass()) {
  103.                 $indexer->addClass($class);
  104.                 $classExporter->export($class);
  105.             }
  106.  
  107.             if (floor(phpversion()) > 3) {
  108.  
  109.                 $indexExporter->exportClasstree($indexer->getClasstree(), $parser->current_baseclass);
  110.  
  111.             } else {
  112.  
  113.                 $classtree = $indexer->getClasstree();
  114.                 $base = $parser->current_baseclass;
  115.                 $indexExporter->exportClasstree($classtree, $base);
  116.  
  117.             }
  118.  
  119.         }
  120.  
  121.         $this->outl("... parsing modules.");
  122.         while ($modulegroup = $parser->getModulegroup()) {    
  123.  
  124.             $moduleAnalyser->setModulegroup( $modulegroup );
  125.             $moduleAnalyser->analyse();
  126.  
  127.             while ($module = $moduleAnalyser->getModule()) {
  128.                 $indexer->addModule($module);
  129.                 $moduleExporter->export($module);
  130.             }
  131.  
  132.             if (floor(phpversion()) > 3) {
  133.  
  134.                 $indexExporter->exportModulegroup($indexer->getModulegroup());
  135.  
  136.             } else {
  137.  
  138.                 $modulegroup = $indexer->getModulegroup();
  139.                 $indexExporter->exportModulegroup($modulegroup);
  140.  
  141.             }
  142.  
  143.         }
  144.  
  145.         $this->outl("... writing packagelist.");
  146.         if (floor(phpversion()) > 3) {
  147.  
  148.             $indexExporter->exportPackagelist($indexer->getPackages());
  149.             $indexExporter->exportElementlist($indexer->getElementlist());
  150.  
  151.         } else {
  152.  
  153.             $packages = $indexer->getPackages();
  154.             $indexExporter->exportPackagelist($packages);
  155.             $elements = $indexer->getElementlist();
  156.             $indexExporter->exportElementlist($elements);
  157.  
  158.         }
  159.  
  160.         $warningExporter->export($parser->warn->getWarnings(), "parser");
  161.         $warningExporter->export($moduleAnalyser->warn->getWarnings(), "moduleanalyser");
  162.         $warningExporter->export($classAnalyser->warn->getWarnings(), "classanalyser");
  163.  
  164.         $this->outl("Parser finished.");
  165.         return true;
  166.     } // end func parse
  167.  
  168.     /**
  169.     * Renders the PHPDoc XML files as HTML files 
  170.     *
  171.     * @param    string  Targetformat, currently only "html" is available.
  172.     * @param    string  Target directory for the html files
  173.     * @param    string  Directory with the html templates
  174.     * @return   bool    $ok
  175.     * @throws   PhpdocError
  176.     * @access   public
  177.     */
  178.     function render($type = "html", $target = "", $template = "") {
  179.  
  180.         $this->outl("Starting to render...");
  181.         $target = ("" == $target) ? $this->target : $this->getCheckedDirname($target);
  182.         $template = ("" == $template) ? $this->templateRoot : $this->getCheckedDirname($template);                
  183.  
  184.         switch (strtolower($type)) {
  185.  
  186.             case "html":
  187.             default:
  188.                 $renderer = new PhpdocHTMLRendererManager($target, $template, $this->application, $this->targetFileSuffix);
  189.                 break;
  190.         }
  191.  
  192.         $fileHandler         = new PhpdocFileHandler;
  193.         $files = $fileHandler->getFilesInDirectory($target, "xml");
  194.         $len = strlen($target);
  195.  
  196.         $tpl = new IntegratedTemplate($this->templateRoot);
  197.         $tpl->loadTemplateFile("xmlfiles.html");
  198.         $tpl->setCurrentBlock("file_loop");
  199.  
  200.         // Do not change the file prefixes!
  201.         reset($files);
  202.         while (list($k, $file) = each($files)) {
  203.  
  204.             $tpl->setVariable("FILE", substr($file, $len));
  205.             $tpl->parseCurrentBlock();
  206.  
  207.             if ("class_" == substr($file, $len, 6)) {
  208.  
  209.                 $renderer->render(substr($file, $len), "class");
  210.  
  211.             } else if ("module_" == substr($file, $len, 7)) {
  212.  
  213.                 $renderer->render(substr($file, $len), "module");
  214.  
  215.             } else if ("classtree_" == substr($file, $len, 10)) {
  216.  
  217.                 $renderer->render(substr($file, $len), "classtree");
  218.  
  219.             }    else if ("modulegroup_" ==  substr($file, $len, 12)) {
  220.  
  221.                 $renderer->render(substr($file, $len), "modulegroup");
  222.  
  223.             } else if ("warnings_" == substr($file, $len, 9)) {
  224.  
  225.                 $renderer->render(substr($file, $len), "warning");
  226.  
  227.             }
  228.  
  229.         }
  230.  
  231.         $renderer->finish();    
  232.         $fileHandler->createFile($target."phpdoc_xmlfiles".$this->targetFileSuffix, $tpl->get());
  233.  
  234.         $this->outl($this->finishInstructions);
  235.         return true;
  236.     } // end func render
  237.  
  238. } // end class Phpdoc
  239. ?>