Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some improvements #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 79 additions & 29 deletions dBug.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/*********************************************************************************************************************\
* LAST UPDATE
* ============
* Jan 25, 2012 by maliayas
* Sep 29, 2011 by maliayas
* July 25, 2011 by maliayas
* March 22, 2007
*
*
Expand Down Expand Up @@ -96,12 +99,12 @@ function getVariableName() {

if(isset($arrFile)) {
$arrLines = file($arrFile["file"]);
$code = $arrLines[($arrFile["line"]-1)];
$code = @$arrLines[($arrFile["line"]-1)];

//find call to dBug class
preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches);
preg_match('/\bnew\s+dBug\s*\(\s*(.+?)\s*\)\s*;/i', $code, $arrMatches);

return $arrMatches[1];
return @$arrMatches[1];
}
return "";
}
Expand All @@ -121,10 +124,10 @@ function makeTableHeader($type,$header,$colspan=2) {
}

//create the table row header
function makeTDHeader($type,$header) {
function makeTDHeader($type,$header, $title = '') {
$str_d = ($this->bCollapsed) ? " style=\"display:none\"" : "";
echo "<tr".$str_d.">
<td valign=\"top\" onClick='dBug_toggleRow(this)' class=\"dBug_".$type."Key\">".$header."</td>
<td valign=\"top\" onClick='dBug_toggleRow(this)' class=\"dBug_".$type."Key\"" . (! empty($title) ? ' title="' . htmlspecialchars($title) . '"' : '') . ">".$header."</td>
<td>";
}

Expand Down Expand Up @@ -161,21 +164,26 @@ function checkType($var) {
$this->varIsBoolean($var);
break;
default:
$var=($var=="") ? "[empty string]" : $var;
echo "<table cellspacing=0><tr>\n<td>".$var."</td>\n</tr>\n</table>\n";
$this->makeTableHeader('simpleVar',gettype($var));
$var=($var==="") ? "[empty string]" : $var;
//echo "<table cellspacing=0><tr>\n<td>".$var."</td>\n</tr>\n</table>\n";
echo '<tr><td>' . htmlspecialchars($var) . '</td></tr>';
echo "</table>";

break;
}
}

//if variable is a NULL type
function varIsNULL() {
echo "NULL";
$this->makeTableHeader('simpleVar',"null");
echo "</table>";
}

//if variable is a boolean type
function varIsBoolean($var) {
$var=($var==1) ? "TRUE" : "FALSE";
echo $var;
$this->makeTableHeader('simpleVar',($var==1) ? "true" : "false");
echo "</table>";
}

//if variable is an array type
Expand All @@ -199,7 +207,7 @@ function varIsArray($var) {
$this->checkType($value);
else {
$value=(trim($value)=="") ? "[empty string]" : $value;
echo $value;
echo htmlspecialchars($value);
}
echo $this->closeTDRow();
}
Expand All @@ -216,32 +224,64 @@ function varIsObject($var) {
$this->makeTableHeader("object","object");

if(is_object($var)) {
$arrObjVars=get_object_vars($var);
foreach($arrObjVars as $key=>$value) {

$value=(!is_object($value) && !is_array($value) && trim($value)=="") ? "[empty string]" : $value;
$this->makeTDHeader("object",$key);
$varRef = new ReflectionObject($var);

$props = $varRef->getProperties();
foreach($props as $prop) {
$prop->setAccessible(true);
$propValue = $prop->getValue($var);
$propName = $prop->getName();
$propModifiers = implode(' ', Reflection::getModifierNames($prop->getModifiers()));
$propAttr = $prop->isPublic() ? '+' : ($prop->isPrivate() ? '-' : '#');
$propAttr = '[' . $propAttr . ($prop->isStatic() ? 'S' : '') . '] ';

$propValue=(gettype($propValue) == "string" && trim($propValue)==="") ? "[empty string]" : $propValue;
$this->makeTDHeader("object",$propAttr . $propName, $propModifiers);

//check for recursion
if(is_object($value)||is_array($value)) {
$var_ser = serialize($value);
if(is_object($propValue)||is_array($propValue)) {
$var_ser = serialize($propValue);
if(in_array($var_ser, $this->arrHistory, TRUE)) {
$value = (is_object($value)) ? "*RECURSION* -> $".get_class($value) : "*RECURSION*";
$propValue = (is_object($propValue)) ? "*RECURSION* -> $".get_class($propValue) : "*RECURSION*";

}
}
if(in_array(gettype($value),$this->arrType))
$this->checkType($value);
else echo $value;
if(in_array(gettype($propValue),$this->arrType))
$this->checkType($propValue);
else echo htmlspecialchars($propValue);
echo $this->closeTDRow();
}

$consts = $varRef->getConstants();
foreach($consts as $key => $const) {
$const=(gettype($const) == "string" && $const === "") ? "[empty string]" : $const;
$this->makeTDHeader("object",'[C] ' . $key);

echo htmlspecialchars($const);
echo $this->closeTDRow();
}
$arrObjMethods=get_class_methods(get_class($var));
foreach($arrObjMethods as $key=>$value) {
$this->makeTDHeader("object",$value);
echo "[function]".$this->closeTDRow();

$methods = $varRef->getMethods();
foreach($methods as $method) {
$method->setAccessible(true);
$methodName = $method->name;
$methodModifiers = implode(' ', Reflection::getModifierNames($method->getModifiers()));
$methodAttr = $method->isPublic() ? '+' : ($method->isPrivate() ? '-' : '#');
$methodAttr = '[' . $methodAttr
. ($method->isStatic() ? 'S' : '')
. ($method->isAbstract() ? 'A' : '')
. ($method->isFinal() ? 'F' : '') . '] ';

$this->makeTDHeader("object", $methodAttr . $methodName, $methodModifiers);

echo htmlspecialchars('[method]');
echo $this->closeTDRow();
}

} else {
echo "<tr><td>".$this->error("object").$this->closeTDRow();
}
else echo "<tr><td>".$this->error("object").$this->closeTDRow();

array_pop($this->arrHistory);
echo "</table>";
}
Expand Down Expand Up @@ -478,22 +518,32 @@ function dBug_toggleTable(source) {
</script>

<style type="text/css">
table.dBug_array,table.dBug_object,table.dBug_resource,table.dBug_resourceC,table.dBug_xml {
table.dBug_array,table.dBug_object,table.dBug_resource,table.dBug_resourceC,table.dBug_xml,
table.dBug_simpleVar{
font-family:Verdana, Arial, Helvetica, sans-serif; color:#000000; font-size:12px;
margin-bottom: 4px;
}

.dBug_arrayHeader,
.dBug_objectHeader,
.dBug_resourceHeader,
.dBug_resourceCHeader,
.dBug_xmlHeader
.dBug_xmlHeader,
.dBug_simpleVarHeader
{ font-weight:bold; color:#FFFFFF; cursor:pointer; }

.dBug_arrayKey,
.dBug_objectKey,
.dBug_simpleVarKey,
.dBug_xmlKey
{ cursor:pointer; }

/* simpleVar: null,boolean,string,integer,double etc... */
table.dBug_simpleVar { background-color:#006600; }
table.dBug_simpleVar td { background-color:#FFFFFF; }
table.dBug_simpleVar td.dBug_simpleVarHeader { background-color:#009900; }
table.dBug_simpleVar td.dBug_simpleVarKey { background-color:#CCFFCC; }

/* array */
table.dBug_array { background-color:#006600; }
table.dBug_array td { background-color:#FFFFFF; }
Expand Down