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