source: classes/phing/tasks/ext/phpdoc/PhingPhpDocumentorSetup.php @ ed3ff78

Last change on this file since ed3ff78 was ed3ff78, checked in by Michiel Rook <mrook@…>, 4 years ago

Documentation fixes

  • Property mode set to 100644
File size: 8.6 KB
Line 
1<?php
2/**
3 * $Id$
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
22/**
23 * Phing subclass of the phpDocumentor_setup class provided with PhpDocumentor to work around limitations in PhpDocumentor API.
24 *
25 * This class is necessary because phpDocumentor_setup does not expose a complete API for setting configuration options.  Because
26 * this class must directly modify some "private" GLOBAL(!) configuration variables, it is liable to break if the PhpDocumentor
27 * internal implementation changes.  Obviously this is far from ideal, but there's also no solution given the inflexibility of the
28 * PhpDocumentor design.
29 *
30 * @author Hans Lellelid <hans@xmpl.org>@author hans
31 * @version $Id$
32 * @package phing.tasks.ext.phpdoc
33 */
34class PhingPhpDocumentorSetup extends phpDocumentor_setup {
35   
36    /**
37     * Constructs a new PhingPhpDocumentorSetup.
38     *
39     * @param string $configDir Directory in which to look for configuration files.
40     * @param object $task              The task we're working with, so we can pass it on to the ErrorTracker
41     */
42    public function __construct($configdir = null, $task) {
43        global $_phpDocumentor_cvsphpfile_exts, $_phpDocumentor_setting, $_phpDocumentor_phpfile_exts;
44       
45        $this->setup = new Io();
46        $this->render = new phpDocumentor_IntermediateParser("Default Title");
47       
48        $GLOBALS['_phpDocumentor_install_dir'] = $configdir;
49        $this->parseIni();
50       
51        // These redundant-looking lines seem to actually make a difference.
52        // See: http://phing.info/trac/ticket/150
53        $_phpDocumentor_phpfile_exts = $GLOBALS['_phpDocumentor_phpfile_exts'];
54        $_phpDocumentor_cvsphpfile_exts = $GLOBALS['_phpDocumentor_cvsphpfile_exts'];
55
56        if (tokenizer_ext) {
57            $this->parse = new phpDocumentorTParser();
58        } else {
59            $this->parse = new Parser();
60        }
61       
62        $this->setMemoryLimit();
63       
64        include_once 'phing/tasks/ext/phpdoc/PhingPhpDocumentorErrorTracker.php';
65       
66        // Inject our own error tracker to PhpDocumentor
67        $GLOBALS['phpDocumentor_errors'] = new PhingPhpDocumentorErrorTracker;
68        $GLOBALS['phpDocumentor_errors']->setTask($task);
69       
70    }
71   
72    /**
73     * Set whether to generate sourcecode for each file parsed.
74     *
75     * This method exists as a hack because there is no API exposed for this in PhpDocumentor.
76     * Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
77     * is subject to break if PhpDocumentor internals changes. 
78     *
79     * @param bool $b
80     */
81    public function setGenerateSourcecode($b) {
82        global $_phpDocumentor_setting;
83        $_phpDocumentor_setting['sourcecode'] = (boolean) $b;
84    }
85   
86    /**
87     * Set an array of README/INSTALL/CHANGELOG file paths.
88     *
89     * This method exists as a hack because there is no API exposed for this in PhpDocumentor.
90     * Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
91     * is subject to break if PhpDocumentor internals changes. 
92     *
93     * @param array $files Absolute paths to files.
94     */
95    public function setRicFiles($files) {
96        global $_phpDocumentor_RIC_files;
97        $_phpDocumentor_RIC_files = $files;
98    }
99   
100    /**
101     * Set comma-separated list of tags to ignore.
102     *
103     * This method exists as a hack because there is no API exposed for this in PhpDocumentor.
104     * Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
105     * is subject to break if PhpDocumentor internals changes. 
106     *
107     * @param string $tags
108     */
109    public function setIgnoreTags($tags) {
110        global $_phpDocumentor_setting; 
111        $ignoretags = explode(',', $tags);
112        $ignoretags = array_map('trim', $ignoretags);
113        $tags = array();
114        foreach($ignoretags as $tag) {
115            if (!in_array($tag,array('@global', '@access', '@package', '@ignore', '@name', '@param', '@return', '@staticvar', '@var')))
116                $tags[] = $tag;
117        }
118        $_phpDocumentor_setting['ignoretags'] = $tags;
119    }
120   
121    /**
122     * Set whether to parse dirs as PEAR repos.
123     *
124     * This method exists as a hack because there is no API exposed for this in PhpDocumentor.
125     * Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
126     * is subject to break if PhpDocumentor internals changes. 
127     *
128     * @param bool $b
129     */
130    public function setPear($b) {
131        global $_phpDocumentor_setting;
132        $_phpDocumentor_setting['pear'] = (boolean) $b;
133    }
134   
135    /**
136     * Set fullpath to directory to look in for examples.
137     *
138     * This method exists as a hack because there is no API exposed for this in PhpDocumentor.
139     * Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
140     * is subject to break if PhpDocumentor internals changes. 
141     *
142     * @param string $dir
143     */
144    public function setExamplesDir($dir) {
145        global $_phpDocumentor_setting;
146        $_phpDocumentor_setting['examplesdir'] = $dir;
147    }
148   
149    /**
150     * Sets the default package name.
151     *
152     * This method exists as a hack because there is no API exposed for this in PhpDocumentor.
153     * Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
154     * is subject to break if PhpDocumentor internals changes. 
155     *
156     * @param string $name
157     */
158    public function setDefaultPackageName($name) {
159        $GLOBALS['phpDocumentor_DefaultPackageName'] = trim($name);
160    }
161   
162    /**
163     * Sets the default category name.
164     *
165     * This method exists as a hack because there is no API exposed for this in PhpDocumentor.
166     * Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
167     * is subject to break if PhpDocumentor internals changes. 
168     *
169     * @param string $name
170     */
171    public function setDefaultCategoryName($name) {
172        $GLOBALS['phpDocumentor_DefaultCategoryName'] = trim($name);
173    }
174   
175    /**
176     * Enables quiet mode.
177     *
178     * This method exists as a hack because the API exposed for this method in PhpDocumentor
179     * doesn't work correctly.
180     *
181     * Note that because we are setting a "private" GLOBAL(!!) config var with this value, this
182     * is subject to break if PhpDocumentor internals changes. 
183     *
184     */
185    public function setQuietMode() {
186        global $_phpDocumentor_setting;
187        $_phpDocumentor_setting['quiet'] = true;
188        parent::setQuietMode();
189    }
190
191    /**
192     * Control whether or not warnings will be shown for undocumented elements.
193     * Useful for identifying classes and methods that haven't yet been
194     * documented.
195     *
196     * @param  bool  $bEnable
197     */
198    public function setUndocumentedelements($bEnable) {
199        $this->render->setUndocumentedElementWarningsMode($bEnable);
200    }
201
202    /**
203     * custom tags, will be recognized and put in tags[] instead of
204     * unknowntags[]
205     *
206     * This method exists as a hack because the API exposed for this method in
207     * PhpDocumentor doesn't work correctly.
208     *
209     * Note that because we are setting a "private" GLOBAL(!!) config var with
210     * this value, this is subject to break if PhpDocumentor internals changes.
211     *
212     * @param  string  $sCustomtags
213     */
214    public function setCustomtags($sCustomtags) {
215        global $_phpDocumentor_setting;
216        $_phpDocumentor_setting['customtags'] = $sCustomtags;
217    }
218   
219    /**
220     * Files to ignore
221     *
222     * @param  string  $sIgnore
223     */
224    public function setIgnore($sIgnore) {
225        global $_phpDocumentor_setting;
226        $_phpDocumentor_setting['ignore'] = $sIgnore;
227    }
228}
Note: See TracBrowser for help on using the repository browser.