Exemple #1
0
 function createDocs($title = false)
 {
     $this->parse_start_time = time();
     global $_phpDocumentor_setting;
     if (!$this->render) {
         $this->render = new phpDocumentor_IntermediateParser($title);
     }
     // setup ignore  list
     $this->ignore_files = array();
     if (isset($_phpDocumentor_setting['ignore'])) {
         $this->setIgnore($_phpDocumentor_setting['ignore']);
     }
     $this->parse->subscribe("*", $this->render);
     // parse the directory
     if (!empty($this->files)) {
         $files = explode(",", $this->files);
         foreach ($files as $file) {
             $file = trim($file);
             $test = $this->setup->getAllFiles($file);
             if ($test) {
                 foreach ($test as $file) {
                     $file = trim($file);
                     $dir = realpath(dirname($file));
                     $dir = strtr($dir, "\\", "/");
                     $dir = str_replace('//', '/', $dir);
                     // strip trailing directory seperator
                     if (substr($dir, -1) == "/" || substr($dir, -1) == "\\") {
                         $dir = substr($dir, 0, -1);
                     }
                     $file = strtr(realpath($file), "\\", "/");
                     $file = str_replace('//', '/', $file);
                     if (!$this->setup->checkIgnore(basename($file), dirname($file), $this->ignore_files, true, $this->ignoresymlinks)) {
                         $filelist[] = str_replace('\\', '/', $file);
                     } else {
                         phpDocumentor_out("File {$file} Ignored\n");
                         flush();
                     }
                 }
             } else {
                 $dir = dirname(realpath($file));
                 $dir = strtr($dir, "\\", "/");
                 $dir = str_replace('//', '/', $dir);
                 // strip trailing directory seperator
                 if (substr($dir, -1) == "/" || substr($dir, -1) == "\\") {
                     $dir = substr($dir, 0, -1);
                 }
                 $base = count(explode("/", $dir));
                 $file = strtr(realpath($file), "\\", "/");
                 $file = str_replace('//', '/', $file);
                 flush();
                 if (!$this->setup->checkIgnore(basename($file), dirname($file), $this->ignore_files, true, $this->ignoresymlinks)) {
                     $filelist[] = str_replace('\\', '/', $file);
                 } else {
                     phpDocumentor_out("File {$file} Ignored\n");
                     flush();
                 }
             }
         }
     }
     if (!empty($this->dirs)) {
         $dirs = explode(",", $this->dirs);
         foreach ($dirs as $dir) {
             $olddir = $dir;
             $dir = realpath($dir);
             if (!$dir) {
                 phpDocumentor_out('ERROR: "' . $olddir . '" does not exist, skipping');
                 continue;
             }
             $dir = trim($dir);
             $dir = strtr($dir, "\\", "/");
             $dir = str_replace('//', '/', $dir);
             // strip trailing directory seperator
             if (substr($dir, -1) == "/" || substr($dir, -1) == "\\") {
                 $dir = substr($dir, 0, -1);
             }
             $files = $this->setup->dirList($dir, $this->hidden, $this->ignoresymlinks);
             if (is_array($files)) {
                 foreach ($files as $file) {
                     $file = strtr($file, '\\', '/');
                     // file's subpath, relative to $dir
                     $file_subpath = str_replace('\\', '/', realpath(dirname($file)));
                     $file_subpath = preg_replace('[\\/]', DIRECTORY_SEPARATOR, $file_subpath);
                     $file_subpath = preg_replace('~^' . preg_quote($dir, '~') . '~', '', $file_subpath);
                     if (!$this->setup->checkIgnore(basename($file), $file_subpath, $this->ignore_files, true, $this->ignoresymlinks)) {
                         $filelist[] = $file;
                     } else {
                         phpDocumentor_out("File {$file} Ignored\n");
                         flush();
                     }
                 }
             }
         }
     }
     if (isset($filelist)) {
         if (PHPDOCUMENTOR_WINDOWS) {
             // case insensitive array_unique
             usort($filelist, 'strnatcasecmp');
             reset($filelist);
             $newarray = array();
             $i = 0;
             $element = current($filelist);
             for ($n = 0; $n < sizeof($filelist); $n++) {
                 if (strtolower(next($filelist)) != strtolower($element)) {
                     $newarray[$i] = $element;
                     $element = current($filelist);
                     $i++;
                 }
             }
             $filelist = $newarray;
         } else {
             $filelist = array_unique($filelist);
         }
         $base = count(explode("/", $source_base = $this->setup->getBase($filelist)));
         define("PHPDOCUMENTOR_BASE", $source_base);
         list($filelist, $ric) = $this->setup->getReadmeInstallChangelog($source_base, $filelist);
         phpDocumentor_out("\n\nGrabbing README/INSTALL/CHANGELOG\n");
         flush();
         foreach ($ric as $file) {
             phpDocumentor_out(basename($file) . '...');
             flush();
             $fp = fopen($file, 'r');
             $contents = fread($fp, filesize($file));
             $this->render->HandleEvent(PHPDOCUMENTOR_EVENT_README_INSTALL_CHANGELOG, array(basename($file), $contents));
             fclose($fp);
         }
         phpDocumentor_out("\ndone\n");
         flush();
         list($filelist, $tutorials) = $this->setup->getTutorials($filelist);
         phpDocumentor_out("\n\nTutorial/Extended Documentation Parsing Stage\n\n");
         flush();
         if (count($tutorials)) {
             $tuteparser = new XMLPackagePageParser();
             $tuteparser->subscribe('*', $this->render);
             foreach ($tutorials as $tutorial) {
                 switch ($tutorial['tutetype']) {
                     case 'pkg':
                     case 'cls':
                     case 'proc':
                         switch ($tutorial['tutetype']) {
                             case 'pkg':
                                 $ptext = 'Package-level Docs ';
                                 if (!empty($tutorial['subpackage'])) {
                                     $ptext = 'Sub-Package Docs ';
                                 }
                                 break;
                             case 'cls':
                                 $ptext = 'Class-level Docs ';
                                 break;
                             case 'proc':
                                 $ptext = 'Procedural-level Docs ';
                                 break;
                         }
                         $fp = @fopen($tutorial['path'], "r");
                         if ($fp) {
                             $ret = fread($fp, filesize($tutorial['path']));
                             // fix 1151650
                             if (stristr($ret, "utf-8") !== "") {
                                 $ret = utf8_decode($ret);
                             }
                             fclose($fp);
                             unset($fp);
                             phpDocumentor_out('Parsing ' . $ptext . $tutorial['path'] . '...');
                             flush();
                             $tuteparser->parse($ret, $tutorial);
                             phpDocumentor_out("done\n");
                             flush();
                         } else {
                             phpDocumentor_out('Error ' . $ptext . $tutorial['path'] . ' doesn\'t exist' . "\n");
                             flush();
                         }
                     default:
                         break;
                 }
             }
         }
         phpDocumentor_out("done\n");
         flush();
         phpDocumentor_out("\n\nGeneral Parsing Stage\n\n");
         flush();
         foreach ($filelist as $file) {
             phpDocumentor_out("Reading file {$file}");
             flush();
             $this->parse->parse($a = $this->setup->readPhpFile($file, $this->render->quietMode), $file, $base, $this->packages);
         }
         $b = time() - $this->parse_start_time;
         phpDocumentor_out("done\n");
         flush();
         // render output
         phpDocumentor_out("\nConverting From Abstract Parsed Data\n");
         flush();
         $this->render->output();
         $a = time() - $this->parse_start_time;
         $c = $a - $b;
         phpDocumentor_out("\nParsing time: {$b} seconds\n");
         phpDocumentor_out("\nConversion time: {$c} seconds\n");
         phpDocumentor_out("\nTotal Documentation Time: {$a} seconds\n");
         phpDocumentor_out("done\n");
         flush();
     } else {
         print "\nERROR: nothing parsed\n";
         exit;
     }
 }