changed git call from https to git readonly
[atutor.git] / mods / phpdoc / PHPDoc / core / PhpdocObject.php
1 <?php\r
2 /**\r
3 * Common base class of all phpdoc classes\r
4 *\r
5 * As a kind of common base class PhpdocObject holds \r
6 * configuration values (e.g. error handling) and debugging\r
7 * methods (e.g. introspection()). It does not have a constructor,\r
8 * so you can always inheritig Phpdoc classes from this \r
9 * class without any trouble.\r
10 *  \r
11 * @author               Ulf Wendel <ulf.wendel@phpdoc.de>\r
12 * @version      $Id: PhpdocObject.php,v 1.2 2000/12/03 20:30:42 uw Exp $\r
13 * @package      PHPDoc\r
14 */\r
15 class PhpdocObject {\r
16 \r
17         /** \r
18         * Variable containing the latest exceptions.\r
19         *\r
20         * The way PHPDoc handles errors is a little different from the\r
21         * official PEAR way. PHPDoc methods do not return \r
22         * error objects but save them to the class variable $err and try\r
23         * to return a value that indicates that an error occured.\r
24         *\r
25         * @var          array\r
26         * @access       public\r
27         */\r
28         var $err = array();\r
29 \r
30         /**\r
31         * Default applicationname for the generated HTML files.\r
32         * \r
33         * @var string   \r
34         */\r
35         var $application = "PHPDoc";\r
36         \r
37         /**\r
38         * Use to save warnings.\r
39         * \r
40         * @var  array\r
41         */\r
42         var $warn;\r
43         \r
44         /**\r
45         * Flag determining wheter to print some status messages or not (default: false)\r
46         *\r
47         * @var          boolean $flag_output\r
48         * @see          setFlagOutput()\r
49         * @since  0.3\r
50         */\r
51         var $flag_output = false;\r
52 \r
53         /**\r
54         * Sets the output flag - if set to true out() and outl() print messages\r
55         *\r
56         * @param        boolean $flagOutput\r
57         * @access       public\r
58         * @see          $flag_output, out(), outl()\r
59         * @since        0.3     \r
60         */\r
61         function setFlagOutput($flagOutput) {\r
62                 $this->flag_output = ($flagOutput) ? true : false;\r
63         } // end func setFlagOutput\r
64         \r
65         /**\r
66         * Print a string and flushes the output buffer\r
67         * @param        string  $message\r
68         */\r
69         function out($message) {\r
70                 if (false == $this->flag_output)\r
71                         return;\r
72                         \r
73                 print $message;\r
74                 flush();\r
75         } // end func out\r
76         \r
77         /**\r
78         * Encodes an element name so that it can be used as a file name.\r
79         * @param        string  element name\r
80         * @return       string  url name\r
81         */\r
82         function nameToUrl($name) {\r
83                 return preg_replace("@[\s\./\\:]@", "_", $name);\r
84         } // end func nameToUrl\r
85 \r
86         \r
87         /**\r
88         * Print a string, the specified HTML line break sign and flushes the output buffer\r
89         * @param        string  $message\r
90         */\r
91         function outl($message) {\r
92                 if (false == $this->flag_output) \r
93                         return;\r
94                         \r
95                 print "$message\n";\r
96                 flush();\r
97         } // end func outl\r
98         \r
99         /**\r
100         * Dumps objects and arrays.\r
101         * \r
102         * Use this function to get an idea of the internal datastructures used. \r
103         * The function dumps arrays and objects. It renders the content in \r
104         * an HTML table. Play with it, you'll see it's very helpful\r
105         * for debugging.\r
106         * \r
107         * @param        string  $title  Optional title used in the HTML Table\r
108         * @param        mixed           $data           Optional array or object that you want to dump. \r
109         *                                                                                               Fallback to $this.\r
110         * @param        boolean $userfunction   Optional flag. If set to false userfunction\r
111         *                                                                                                       in an object are not shown (default). If set to \r
112         *                                                                                                       true, userfunctions are rendered\r
113         *\r
114         *       @access         public\r
115         * @version      0.2\r
116         */\r
117         function introspection($title="", $data = "", $userfunction = true) {\r
118                 \r
119                 if (""==$data)\r
120                         $data = $this;\r
121                 \r
122                 printf('<table border="1" cellspacing="4" cellpadding="4" bordercolor="Silver">%s',\r
123                                                         $this->CR_HTML\r
124                                                 );      \r
125                                                 \r
126                 if (""!=$title)\r
127                         printf('<tr>%s<td colspan=4><b>%s</b></td>%s</tr>%s', \r
128                                                                 $this->CR_HTML,\r
129                                                                 $title,\r
130                                                                 $this->CR_HTML,\r
131                                                                 $this->CR_HTML\r
132                                                         );\r
133                 \r
134                 reset($data);\r
135                 while (list($k, $v)=each($data)) {\r
136                 \r
137                         if ("user function"==gettype($v) && !$userfunction) \r
138                                 continue;\r
139                         \r
140                         if (is_array($v) || is_object($v)) {\r
141                                 \r
142                                 \r
143                                 $color="navy";\r
144                                         \r
145                                 printf('<tr>\r
146                                                                         <td align="left" valign="top">\r
147                                                                                 <font color="%s"><pre><b>%s</b></pre></font>\r
148                                                                         </td>\r
149                                                                         <td align="left" valign="top"><font color="%s"><pre>=></pre></font></td>\r
150                                                                         <td align="left" valign="top" colspan=2>',\r
151                                                                                 $color,\r
152                                                                                 $k,\r
153                                                                                 $color,\r
154                                                                                 str_replace("<", "&lt;", $v)\r
155                                                                 );\r
156                                                                 \r
157                                 $this->introspection("", $v, $userfunction);\r
158                                         \r
159                                 printf('</td>%s</tr>%s', $this->CR_HTML, $this->CR_HTML);\r
160                                 \r
161                         }       else {\r
162                                 \r
163                                 $color="black";\r
164                                         \r
165                                 printf('<tr>\r
166                                                                         <td align="left" valign="top">\r
167                                                                                 <font color="%s"><pre><b>%s</b></pre></font>\r
168                                                                         </td>\r
169                                                                         <td align="left" valign="top"><pre><font color="%s">=></pre></font></td>\r
170                                                                         <td align="left" valign="top"><pre><font color="%s">[%s]</font></pre></td>\r
171                                                                         <td align="left" valign="top"><pre><font color="%s">"%s"</font></pre></td>\r
172                                                                 </tr>',\r
173                                                                         $color,\r
174                                                                         $k,\r
175                                                                         $color,\r
176                                                                         $color,\r
177                                                                         gettype($v),\r
178                                                                         $color,\r
179                                                                         str_replace("<", "&lt;", $v)\r
180                                                                 );\r
181                         }\r
182                 }\r
183                 print '</table>'.$this->CR_HTML;\r
184         } // end func introspection\r
185         \r
186 } // end class PhpdocObject\r
187 ?>