source: classes/phing/tasks/ext/docblox/DocBloxTask.php @ 557a424

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

Refs #690 - update / deps to work with current docblox master / forthcoming version 0.11

  • Property mode set to 100644
File size: 4.9 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
22require_once 'phing/Task.php';
23require_once 'phing/system/io/FileOutputStream.php';
24
25/**
26 * DocBlox Task (http://www.docblox-project.org)
27 *
28 * @author    Michiel Rook <mrook@php.net>
29 * @version   $Revision$
30 * @since     2.4.6
31 * @package   phing.tasks.ext.docblox
32 */
33class DocBloxTask extends Task
34{
35    /**
36     * List of filesets
37     * @var FileSet[]
38     */
39    private $filesets = array();
40   
41    /**
42     * Destination/target directory
43     * @var string
44     */
45    private $destDir = "";
46   
47    /**
48     * Title of the project
49     * @var string
50     */
51    private $title = "";
52   
53    /**
54     * Force DocBlox to be quiet
55     * @var boolean
56     */
57    private $quiet = true;
58   
59    /**
60     * Nested creator, adds a set of files (nested fileset attribute).
61     */
62    public function createFileSet()
63    {
64        $num = array_push($this->filesets, new FileSet());
65        return $this->filesets[$num-1];
66    }
67   
68    /**
69     * Sets destination/target directory
70     * @param string $destDir
71     */
72    public function setDestDir($destDir)
73    {
74        $this->destDir = (string) $destDir;
75    }
76   
77    /**
78     * Sets the title of the project
79     * @param strings $title
80     */
81    public function setTitle($title)
82    {
83        $this->title = (string) $title;
84    }
85   
86    /**
87     * Forces DocBlox to be quiet
88     * @param boolean $quiet
89     */
90    public function setQuiet($quiet)
91    {
92        $this->quiet = (boolean) $quiet;
93    }
94   
95    /**
96     * Finds and initializes the DocBlox installation
97     */
98    private function initializeDocBlox()
99    {
100        $docbloxPath = null;
101       
102        foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
103            $testpath = $path . DIRECTORY_SEPARATOR . 'DocBlox' . DIRECTORY_SEPARATOR . 'src';
104            if (file_exists($testpath)) {
105                $docbloxPath = $testpath;
106                break;
107            }
108        }
109        if (empty($docbloxPath)) {
110            throw new BuildException("Please make sure DocBlox is installed and on the include_path.", $this->getLocation());
111        }
112       
113        require_once 'Zend/Loader/Autoloader.php';
114       
115        set_include_path($docbloxPath . PATH_SEPARATOR . get_include_path());
116       
117        $autoloader = Zend_Loader_Autoloader::getInstance();
118        $autoloader->registerNamespace('DocBlox_');
119    }
120   
121    /**
122     * Build a list of files (from the fileset elements) and call the DocBlox parser
123     * @return string
124     */
125    private function parseFiles()
126    {
127        $parser = new DocBlox_Parser();
128        $parser->setTitle($this->title);
129       
130        if ($this->quiet) {
131            $parser->setLogLevel(Zend_Log::CRIT);
132        }
133       
134        $files = array();
135       
136        // filesets
137        foreach ($this->filesets as $fs) {
138            $ds    = $fs->getDirectoryScanner($this->project);
139            $dir   = $fs->getDir($this->project);
140            $srcFiles = $ds->getIncludedFiles();
141           
142            foreach ($srcFiles as $file) {
143                $files[] = $dir . FileSystem::getFileSystem()->getSeparator() . $file;
144            }
145        }
146       
147        $this->log("Will parse " . count($files) . " file(s)", Project::MSG_VERBOSE);
148       
149        return $parser->parseFiles($files);
150    }
151
152    /**
153     * Task entry point
154     * @see Task::main()
155     */
156    public function main()
157    {
158        if (empty($this->destDir)) {
159            throw new BuildException("You must supply the 'destdir' attribute", $this->getLocation());
160        }
161       
162        if (empty($this->filesets)) {
163            throw new BuildException("You have not specified any files to include (<fileset>)", $this->getLocation());
164        }
165       
166        $this->initializeDocBlox();
167       
168        $xml = $this->parseFiles();
169       
170        $transformer = new DocBlox_Transformer();
171       
172        $transformer->setSource($xml);
173        $transformer->setTarget($this->destDir);
174       
175        $transformer->execute();
176       
177        $file->delete();
178    }
179}
Note: See TracBrowser for help on using the repository browser.