PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/docgen.php

https://github.com/zh/statusnet
PHP | 114 lines | 43 code | 13 blank | 58 comment | 13 complexity | 7b76be12a54c603e41988902117c3449 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-3.0, GPL-2.0
  1. #!/usr/bin/env php
  2. <?php
  3. $shortoptions = '';
  4. $longoptions = array('plugin=');
  5. $helptext = <<<ENDOFHELP
  6. Build HTML documentation from doc comments in source.
  7. Usage: docgen.php [options] output-directory
  8. Options:
  9. --plugin=... build docs for given plugin instead of core
  10. ENDOFHELP;
  11. define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
  12. set_include_path(INSTALLDIR . DIRECTORY_SEPARATOR . 'extlib' . PATH_SEPARATOR . get_include_path());
  13. $pattern = "*.php *.inc";
  14. $exclude = 'config.php */extlib/* */local/* */plugins/* */scripts/*';
  15. $plugin = false;
  16. require_once 'Console/Getopt.php';
  17. $parser = new Console_Getopt();
  18. $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
  19. if (PEAR::isError($result)) {
  20. print $result->getMessage() . "\n";
  21. exit(1);
  22. }
  23. list($options, $args) = $result;
  24. foreach ($options as $option) {
  25. $arg = $option[0];
  26. if ($arg == '--plugin') {
  27. $plugin = $options[1];
  28. } else if ($arg == 'h' || $arg == '--help') {
  29. print $helptext;
  30. exit(0);
  31. }
  32. }
  33. if (isset($args[0])) {
  34. $outdir = $args[0];
  35. if (!is_dir($outdir)) {
  36. echo "Output directory $outdir is not a directory.\n";
  37. exit(1);
  38. }
  39. } else {
  40. print $helptext;
  41. exit(1);
  42. }
  43. if ($plugin) {
  44. $exclude = "*/extlib/*";
  45. $indir = INSTALLDIR . "/plugins/" . $plugin;
  46. if (!is_dir($indir)) {
  47. $indir = INSTALLDIR . "/plugins";
  48. $filename = "{$plugin}Plugin.php";
  49. if (!file_exists("$indir/$filename")) {
  50. echo "Can't find plugin $plugin.\n";
  51. exit(1);
  52. } else {
  53. $pattern = $filename;
  54. }
  55. }
  56. } else {
  57. $indir = INSTALLDIR;
  58. }
  59. function getVersion()
  60. {
  61. // define('STATUSNET_VERSION', '0.9.1');
  62. $source = file_get_contents(INSTALLDIR . '/lib/common.php');
  63. if (preg_match('/^\s*define\s*\(\s*[\'"]STATUSNET_VERSION[\'"]\s*,\s*[\'"](.*)[\'"]\s*\)\s*;/m', $source, $matches)) {
  64. return $matches[1];
  65. }
  66. return 'unknown';
  67. }
  68. $replacements = array(
  69. '%%version%%' => getVersion(),
  70. '%%indir%%' => $indir,
  71. '%%pattern%%' => $pattern,
  72. '%%outdir%%' => $outdir,
  73. '%%htmlout%%' => $outdir,
  74. '%%exclude%%' => $exclude,
  75. );
  76. var_dump($replacements);
  77. $template = file_get_contents(dirname(__FILE__) . '/doxygen.tmpl');
  78. $template = strtr($template, $replacements);
  79. $templateFile = tempnam(sys_get_temp_dir(), 'statusnet-doxygen');
  80. file_put_contents($templateFile, $template);
  81. $cmd = "doxygen " . escapeshellarg($templateFile);
  82. $retval = 0;
  83. passthru($cmd, $retval);
  84. if ($retval == 0) {
  85. echo "Done!\n";
  86. unlink($templateFile);
  87. exit(0);
  88. } else {
  89. echo "Failed! Doxygen config left in $templateFile\n";
  90. exit($retval);
  91. }