PageRenderTime 29ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/phing/tasks/ext/phpdoc/PhpDocumentorTask.php

https://github.com/IDCI-Consulting/WebsiteEval
PHP | 460 lines | 197 code | 65 blank | 198 comment | 24 complexity | bc92b0ecd002b9cf55f4d7e7b200ab0e MD5 | raw file
  1. <?php
  2. /**
  3. * $Id: PHPDocumentorTask.php 144 2007-02-05 15:19:00Z hans $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/Task.php';
  22. /**
  23. * Task to run PhpDocumentor.
  24. *
  25. * @author Hans Lellelid <hans@xmpl.org>
  26. * @author Michiel Rook <michiel.rook@gmail.com>
  27. * @version $Id$
  28. * @package phing.tasks.ext.phpdoc
  29. */
  30. class PhpDocumentorTask extends Task
  31. {
  32. /**
  33. * @var string Title for browser window / package index.
  34. */
  35. protected $title;
  36. /**
  37. * @var PhingFile The target directory for output files.
  38. */
  39. protected $destdir;
  40. /**
  41. * @var array FileSet[] Filesets for files to parse.
  42. */
  43. protected $filesets = array();
  44. /**
  45. * @var array FileSet[] Project documentation (README/INSTALL/CHANGELOG) files.
  46. */
  47. protected $projDocFilesets = array();
  48. /**
  49. * @var string Package output format.
  50. */
  51. protected $output;
  52. /**
  53. * @var boolean Whether to generate sourcecode for each file parsed.
  54. */
  55. protected $linksource = false;
  56. /**
  57. * @var boolean Whether to parse private members.
  58. */
  59. protected $parsePrivate = false;
  60. /**
  61. * @var boolean Whether to use javadoc descriptions (more primitive).
  62. */
  63. protected $javadocDesc = false;
  64. /**
  65. * @var PhingFile Base directory for locating template files.
  66. */
  67. protected $templateBase;
  68. /**
  69. * @var boolean Wheter to suppress output.
  70. */
  71. protected $quiet = false;
  72. /**
  73. * @var string Comma-separated list of packages to output.
  74. */
  75. protected $packages;
  76. /**
  77. * @var string Comma-separated list of tags to ignore.
  78. */
  79. protected $ignoreTags;
  80. /**
  81. * @var string Default package name.
  82. */
  83. protected $defaultPackageName;
  84. /**
  85. * @var string Default category name.
  86. */
  87. protected $defaultCategoryName;
  88. /**
  89. * @var PhingFile Directory in which to look for examples.
  90. */
  91. protected $examplesDir;
  92. /**
  93. * @var PhingFile Directory in which to look for configuration files.
  94. */
  95. protected $configDir;
  96. /**
  97. * @var boolean Whether to parse as a PEAR repository.
  98. */
  99. protected $pear = false;
  100. /**
  101. * @var boolean Control whether or not warnings will be shown for
  102. * undocumented elements. Useful for identifying classes and
  103. * methods that haven't yet been documented.
  104. */
  105. protected $undocumentedelements = false;
  106. /**
  107. * @var string custom tags, will be recognized and put in tags[] instead of
  108. * unknowntags[].
  109. */
  110. protected $customtags = '';
  111. /**
  112. * Set the title for the generated documentation
  113. */
  114. public function setTitle($title) {
  115. $this->title = $title;
  116. }
  117. /**
  118. * Set the destination directory for the generated documentation
  119. */
  120. public function setDestdir(PhingFile $destdir) {
  121. $this->destdir = $destdir;
  122. }
  123. /**
  124. * Alias for {@link setDestdir()).
  125. * @see setDestdir()
  126. */
  127. public function setTarget(PhingFile $destdir) {
  128. $this->setDestdir($destdir);
  129. }
  130. /**
  131. * Set the output format (e.g. HTML:Smarty:PHP).
  132. * @param string $output
  133. */
  134. public function setOutput($output) {
  135. $this->output = $output;
  136. }
  137. /**
  138. * Set whether to generate sourcecode for each file parsed
  139. * @param boolean
  140. */
  141. public function setSourcecode($b) {
  142. $this->linksource = $b;
  143. }
  144. /**
  145. * Set whether to suppress output.
  146. * @param boolean $b
  147. */
  148. public function setQuiet($b) {
  149. $this->quiet = $b;
  150. }
  151. /**
  152. * Should private members/classes be documented
  153. * @param boolean
  154. */
  155. public function setParseprivate($parseprivate) {
  156. $this->parsePrivate = $parseprivate;
  157. }
  158. /**
  159. * Whether to use javadoc descriptions (more primitive).
  160. * @param boolean
  161. */
  162. public function setJavadocdesc($javadoc) {
  163. $this->javadocDesc = $javadoc;
  164. }
  165. /**
  166. * Set (comma-separated) list of packages to output.
  167. *
  168. * @param string $packages
  169. */
  170. public function setPackageoutput($packages) {
  171. $this->packages = $packages;
  172. }
  173. /**
  174. * Set (comma-separated) list of tags to ignore.
  175. *
  176. * @param string $tags
  177. */
  178. public function setIgnoretags($tags) {
  179. $this->ignoreTags = $tags;
  180. }
  181. /**
  182. * Set a directory to search for examples in.
  183. * @param PhingFile $d
  184. */
  185. public function setExamplesdir(PhingFile $d) {
  186. $this->examplesDir = $d;
  187. }
  188. /**
  189. * Set a directory to search for configuration files in.
  190. * @param PhingFile $d
  191. */
  192. public function setConfigdir(PhingFile $d) {
  193. $this->configDir = $d;
  194. }
  195. /**
  196. * Sets the default package name.
  197. * @param string $name
  198. */
  199. public function setDefaultpackagename($name) {
  200. $this->defaultPackageName = $name;
  201. }
  202. /**
  203. * Sets the default category name.
  204. * @param string $name
  205. */
  206. public function setDefaultcategoryname($name) {
  207. $this->defaultCategoryName = $name;
  208. }
  209. /**
  210. * Set whether to parse as PEAR repository.
  211. * @param boolean $b
  212. */
  213. public function setPear($b) {
  214. $this->pear = $b;
  215. }
  216. /**
  217. * Creates a FileSet.
  218. * @return FileSet
  219. */
  220. public function createFileset() {
  221. $num = array_push($this->filesets, new FileSet());
  222. return $this->filesets[$num-1];
  223. }
  224. /**
  225. * Creates a readme/install/changelog fileset.
  226. * @return FileSet
  227. */
  228. public function createProjdocfileset() {
  229. $num = array_push($this->projDocFilesets, new FileSet());
  230. return $this->projDocFilesets[$num-1];
  231. }
  232. /**
  233. * Control whether or not warnings will be shown for undocumented elements.
  234. * Useful for identifying classes and methods that haven't yet been
  235. * documented.
  236. * @param boolean $b
  237. */
  238. public function setUndocumentedelements($b) {
  239. $this->undocumentedelements = $b;
  240. }
  241. /**
  242. * custom tags, will be recognized and put in tags[] instead of
  243. * unknowntags[].
  244. *
  245. * @param string $sCustomtags
  246. */
  247. public function setCustomtags($sCustomtags) {
  248. $this->customtags = $sCustomtags;
  249. }
  250. /**
  251. * Set base location of all templates for this parse.
  252. *
  253. * @param PhingFile $destdir
  254. */
  255. public function setTemplateBase(PhingFile $oTemplateBase) {
  256. $this->templateBase = $oTemplateBase;
  257. }
  258. /**
  259. * Searches include_path for PhpDocumentor install and adjusts include_path appropriately.
  260. * @throws BuildException - if unable to find PhpDocumentor on include_path
  261. */
  262. protected function findPhpDocumentorInstall()
  263. {
  264. $found = null;
  265. foreach(explode(PATH_SEPARATOR, get_include_path()) as $path) {
  266. $testpath = $path . DIRECTORY_SEPARATOR . 'PhpDocumentor';
  267. if (file_exists($testpath)) {
  268. $found = $testpath;
  269. break;
  270. }
  271. }
  272. if (!$found) {
  273. throw new BuildException("PhpDocumentor task depends on PhpDocumentor being installed and on include_path.", $this->getLocation());
  274. }
  275. // otherwise, adjust the include_path to path to include the PhpDocumentor directory ...
  276. set_include_path(get_include_path() . PATH_SEPARATOR . $found);
  277. include_once ("phpDocumentor/Setup.inc.php");
  278. if (!class_exists('phpDocumentor_setup')) {
  279. throw new BuildException("Error including PhpDocumentor setup class file.");
  280. }
  281. }
  282. /**
  283. * Load the necessary environment for running PhpDoc.
  284. *
  285. * @throws BuildException - if the phpdoc classes can't be loaded.
  286. */
  287. public function init()
  288. {
  289. $this->findPhpDocumentorInstall();
  290. include_once 'phing/tasks/ext/phpdoc/PhingPhpDocumentorSetup.php';
  291. }
  292. /**
  293. * Main entrypoint of the task
  294. */
  295. function main()
  296. {
  297. $this->validate();
  298. $configdir = $this->configDir ? $this->configDir->getAbsolutePath() : null;
  299. $phpdoc = new PhingPhpDocumentorSetup($configdir);
  300. $this->setPhpDocumentorOptions($phpdoc);
  301. //$phpdoc->readCommandLineSettings();
  302. $phpdoc->setupConverters($this->output);
  303. $phpdoc->createDocs();
  304. }
  305. /**
  306. * Validates that necessary minimum options have been set.
  307. * @throws BuildException if validation doesn't pass
  308. */
  309. protected function validate()
  310. {
  311. if (!$this->destdir) {
  312. throw new BuildException("You must specify a destdir for phpdoc.", $this->getLocation());
  313. }
  314. if (!$this->output) {
  315. throw new BuildException("You must specify an output format for phpdoc (e.g. HTML:frames:default).", $this->getLocation());
  316. }
  317. if (empty($this->filesets)) {
  318. throw new BuildException("You have not specified any files to include (<fileset>) for phpdoc.", $this->getLocation());
  319. }
  320. }
  321. /**
  322. * Sets the options on the passed-in phpdoc setup object.
  323. * @param PhingPhpDocumentorSetup $phpdoc
  324. */
  325. protected function setPhpDocumentorOptions(PhingPhpDocumentorSetup $phpdoc)
  326. {
  327. // Title MUST be set first ... (because it re-initializes the internal state of the PhpDocu renderer)
  328. if ($this->title) {
  329. $phpdoc->setTitle($this->title);
  330. }
  331. if ($this->parsePrivate) {
  332. $phpdoc->setParsePrivate();
  333. }
  334. if ($this->javadocDesc) {
  335. $phpdoc->setJavadocDesc();
  336. }
  337. if ($this->quiet) {
  338. $phpdoc->setQuietMode();
  339. }
  340. if ($this->destdir) {
  341. $phpdoc->setTargetDir($this->destdir->getAbsolutePath());
  342. }
  343. if ($this->packages) {
  344. $phpdoc->setPackageOutput($this->packages);
  345. }
  346. if ($this->templateBase) {
  347. $phpdoc->setTemplateBase($this->templateBase->getAbsolutePath());
  348. }
  349. if ($this->linksource) {
  350. $phpdoc->setGenerateSourcecode($this->linksource);
  351. }
  352. if ($this->examplesDir) {
  353. $phpdoc->setExamplesDir($this->examplesDir->getAbsolutePath());
  354. }
  355. if ($this->ignoreTags) {
  356. $phpdoc->setIgnoreTags($this->ignoreTags);
  357. }
  358. if ($this->defaultPackageName) {
  359. $phpdoc->setDefaultPackageName($this->defaultPackageName);
  360. }
  361. if ($this->defaultCategoryName) {
  362. $phpdoc->setDefaultCategoryName($this->defaultCategoryName);
  363. }
  364. if ($this->pear) {
  365. $phpdoc->setPear($this->pear);
  366. }
  367. // append any files in filesets
  368. $filesToParse = array();
  369. foreach($this->filesets as $fs) {
  370. $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
  371. foreach($files as $filename) {
  372. $f = new PhingFile($fs->getDir($this->project), $filename);
  373. $filesToParse[] = $f->getAbsolutePath();
  374. }
  375. }
  376. //print_r(implode(",", $filesToParse));
  377. $phpdoc->setFilesToParse(implode(",", $filesToParse));
  378. // append any files in filesets
  379. $ricFiles = array();
  380. foreach($this->projDocFilesets as $fs) {
  381. $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
  382. foreach($files as $filename) {
  383. $f = new PhingFile($fs->getDir($this->project), $filename);
  384. $ricFiles[] = $f->getAbsolutePath();
  385. }
  386. }
  387. $phpdoc->setRicFiles($ricFiles);
  388. if ($this->undocumentedelements) {
  389. $phpdoc->setUndocumentedelements($this->undocumentedelements);
  390. }
  391. if ($this->customtags) {
  392. $phpdoc->setCustomtags($this->customtags);
  393. }
  394. }
  395. }