cd5a653431fd5231bec425e5c079df6bec172ca5
[atutor.git] / mods / phpdoc / PHPDoc / core / PhpdocSetupHandler.php
1 <?php\r
2 /**\r
3 * Handles the "setup".\r
4 *\r
5 * This class provides all methods neccessary to "setup" Phpdoc and check the \r
6 * current setup.\r
7\r
8 * @version      $Id: PhpdocSetupHandler.php,v 1.5 2000/12/03 20:30:42 uw Exp $\r
9 * @author               Ulf Wendel <ulf@redsys.de>\r
10 */\r
11 class PhpdocSetupHandler extends PhpdocArgvHandler {\r
12 \r
13         /**\r
14         * Name of the target directory.\r
15         *\r
16         * @var          string  $target\r
17         * @access       private\r
18         */                                                              \r
19         var $target = "";       \r
20         \r
21         /**\r
22         * Name of the application parsed\r
23         *\r
24         * @var  string  $application\r
25         * @see  setApplication()\r
26         */\r
27         var $application = "PHPDoc";\r
28         \r
29         /**\r
30         * Basedir for all file operations\r
31         *\r
32         * @var  string  $basedir\r
33         * @see  setApplication()\r
34         */\r
35         var $basedir = "";\r
36     \r
37         /**\r
38         * Suffix for all rendered files in the application (except for the xml files).\r
39         *\r
40         * @var  string  targetFileSuffix\r
41         * @see  setTargetFileSuffix()\r
42         */\r
43         var     $targetFileSuffix = ".html";\r
44         \r
45         /**\r
46         * Suffix of all source code files in the application\r
47         *\r
48         * If you used other file suffixes than ".php" in you have to override this.\r
49         *\r
50         * variable using setSourceFileSuffix()\r
51         * @var  array   sourceFileSuffix\r
52         * @see  setSourceFileSuffix()\r
53         */\r
54         var     $sourceFileSuffix = array ( "php" );\r
55         \r
56         /**\r
57         * Directory with the php sources to parse.\r
58         *\r
59         * @var  string  \r
60         * @see  setSourceDirectory()\r
61         */\r
62         var $sourceDirectory = "";      \r
63         \r
64         /**\r
65         * Sets the name of the directory with the source to scan.\r
66         *\r
67         * @param        string\r
68         * @access       public\r
69         */\r
70         function setSourceDirectory($sourcedir) {\r
71                 $this->sourceDirectory = $this->getCheckedDirname($sourcedir);\r
72         } // end end func setSourceDirectory\r
73         \r
74         /**\r
75         * Sets the name of the directory with the templates.\r
76         *\r
77         * @param        string\r
78         * @access       public\r
79         */\r
80         function setTemplateDirectory($sourcedir) {\r
81                 $this->templateRoot = $this->getCheckedDirname($sourcedir);\r
82         } // end func setTemplateDirectory\r
83         \r
84         /**\r
85         * Sets the name of your application. \r
86         * \r
87         * The application name gets used on many places in the default templates.\r
88         * \r
89         * @param        string  $application    name of the application\r
90         * @return       bool            $ok\r
91         * @throws       PhpdocError     \r
92         * @access       public\r
93         */      \r
94         function setApplication($application) {\r
95                 if (""==$application) {\r
96                         $this->err[] = new PhpdocError("No application name given.", __FILE__, __LINE__);\r
97                         return false;\r
98                 }\r
99                 \r
100                 $this->application = $application;\r
101                 return true;\r
102         } // end func setApplication\r
103         \r
104         /**\r
105         * Suffix for all rendered files in the application (not for the xml files)\r
106         *\r
107         * By default the the suffix is set to ".html".\r
108         *\r
109         * @param        string  $suffix         string with the suffix\r
110         * @return       bool            $ok\r
111         * @see          $targetFileSuffix\r
112         * @author       Thomas Weinert <subjective@subjective.de>\r
113         */\r
114         function setTargetFileSuffix($suffix) {\r
115                 if ("" != $suffix && "." != $suffix[0]) {\r
116                         $this->err[] = new PhpdocError("Make sure that the file extension starts with a dot.", __FILE__, __LINE__);\r
117                         return false; \r
118                 }\r
119                 \r
120                 $this->targetFileSuffix = $suffix;\r
121                 return true;\r
122         }\r
123 \r
124         /**\r
125         * Suffix of all source code files in the application\r
126         *\r
127         * By default only files with the suffix ".php" are recognized as\r
128         * php source code files and parsed. If you used other\r
129         * suffixes such as ".inc" you have to tell phpdoc to parse\r
130         * them.\r
131         *\r
132         * @param        mixed   $suffix         string with one suffix or array of suffixes\r
133         * @return       bool    $ok\r
134         * @throws       PhpdocError\r
135         * @see          $sourceFileSuffix\r
136         */\r
137         function setSourceFileSuffix($suffix) {\r
138                 if ( (!is_array($suffix) && "" == $suffix) || (is_array($suffix) && 0 == count($suffix)) ) {\r
139                         $this->err[] = new PhpdocError("No suffix specified.", __FILE__, __LINE__);\r
140                         return false;\r
141                 }\r
142                 if (!is_array($suffix)) \r
143                         $suffix = array($suffix);               \r
144                 \r
145                 $this->sourceFileSuffix = $suffix;      \r
146                 return true;\r
147         } // end func setSourceFileSuffix\r
148 \r
149         /**\r
150         * Sets the target where the generated files are saved.\r
151         * \r
152         * @param        string  $target\r
153         * @return       bool            $ok \r
154         * @throws PhpdocError\r
155         * @access       public\r
156         */\r
157         function setTarget($target) {\r
158                 if ("" == $target) {\r
159                         $this->err[] = new PhpdocError("No target specified.", __FILE__, __LINE__);\r
160                         return false;\r
161                 }\r
162                 \r
163                 if (!is_dir($target)) {\r
164                         $ok = mkdir($target, 0755);\r
165                         if (!$ok) {\r
166                                 $this->err[] = new PhpdocError("setTarget(), can't create a directory '$target'.", __FILE__, __LINE__);\r
167                                 return false;\r
168                         }\r
169                 }\r
170                         \r
171                 $this->target = $this->getCheckedDirname($target);\r
172                 return true;\r
173         } // end func setTarget\r
174 \r
175         /**\r
176         * Checks the current status of the object. Are all necessary informations to start parsing available?\r
177         * @param        mixed           $errors\r
178         * @return       array           $errors\r
179         */\r
180         function checkStatus($errors = "") {\r
181                 if (!is_array($errors))\r
182                         $errors = array();\r
183 /*\r
184                                 \r
185                 if (0==count($this->files) && ""==$this->directory) \r
186                         $errors[] = array (\r
187                                                                                                         "msg"   => "No source files or source directory specified.",\r
188                                                                                                         "type"  => "misconfiguration",\r
189                                                                                                         "errno" => 6\r
190                                                                                                 );\r
191                                                                                                 \r
192                 if (0!=count($this->files) && ""!=$this->directory) \r
193                         $errors[] = array(\r
194                                                                                                         "msg"           => "Define eighter some files or a diretory.",\r
195                                                                                                         "type"  => "misconfiguration",\r
196                                                                                                         "errno" => 7\r
197                                                                                         );\r
198         */      \r
199                 return $errors;\r
200         } // end func checkStatus\r
201         \r
202         /**\r
203         * Adds a slash at the end of the given filename if neccessary.\r
204         *\r
205         * @param        string  Directoryname\r
206         * @return       string  Directoryname\r
207         */\r
208         function getCheckedDirname($dirname) {\r
209 \r
210                 if ("" != $dirname && "/" != substr($dirname, -1)) \r
211                         $dirname .= "/";\r
212                         \r
213                 return $dirname;\r
214         } // end func getCheckedDirname\r
215 \r
216 } // end class PhpdocSetupHandler\r
217 ?>